SNAP Library 4.0, Developer Reference  2017-07-27 13:18:06
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
TMMNet Class Reference

Multimodal networks. More...

#include <mmnet.h>

Collaboration diagram for TMMNet:

Classes

class  TCrossNetI
 TCrossNet iterator. Only forward iteration (operator++) is supported. More...
 
class  TCrossNetInit
 
class  TModeNetI
 TModeNet iterator. Only forward iteration (operator++) is supported. More...
 
class  TModeNetInit
 

Public Member Functions

 TMMNet ()
 
 TMMNet (const TMMNet &OtherTMMNet)
 
 TMMNet (TSIn &SIn)
 
int AddModeNet (const TStr &ModeName)
 Adds a mode to the multimodal network. More...
 
int DelModeNet (const TInt &ModeId)
 Deletes a mode from the multimodal network. More...
 
int DelModeNet (const TStr &ModeName)
 
int AddCrossNet (const TStr &ModeName1, const TStr &ModeName2, const TStr &CrossNetName, bool isDir=true)
 Adds a crossnet to the multimodal network. Specify modes by id or names; by default, crossnet is directed. More...
 
int AddCrossNet (const TInt &ModeId1, const TInt &ModeId2, const TStr &CrossNetName, bool isDir=true)
 
int DelCrossNet (const TInt &CrossNetId)
 Deletes a crossnet from the multimodal network. More...
 
int DelCrossNet (const TStr &CrossNet)
 
void Save (TSOut &SOut) const
 Saves the TMMNet to binary stream. More...
 
void ConvertToSparse ()
 
int GetModeId (const TStr &ModeName) const
 Gets the mode id from the mode name. More...
 
TStr GetModeName (const TInt &ModeId) const
 Gets the mode name from the mode id. More...
 
int GetCrossId (const TStr &CrossName) const
 Gets the crossnet id from the crossnet name. More...
 
TStr GetCrossName (const TInt &CrossId) const
 Gets the crossnet name from the crossnet id. More...
 
TModeNetGetModeNetByName (const TStr &ModeName) const
 Gets a reference to the modenet. More...
 
TModeNetGetModeNetById (const TInt &ModeId) const
 
TCrossNetGetCrossNetByName (const TStr &CrossName) const
 Gets a reference to the crossnet. More...
 
TCrossNetGetCrossNetById (const TInt &CrossId) const
 
TCrossNetI GetCrossNetI (const int &Id) const
 Iterator over all crossnets. More...
 
TCrossNetI BegCrossNetI () const
 
TCrossNetI EndCrossNetI () const
 
TModeNetI GetModeNetI (const int &Id) const
 Iterator over all modenets. More...
 
TModeNetI BegModeNetI () const
 
TModeNetI EndModeNetI () const
 
int GetModeNets ()
 Returns the number of modes in the multimodal network. More...
 
int GetCrossNets ()
 Returns the number of crossnets in the multimodal network. More...
 
PMMNet GetSubgraphByCrossNet (TStrV &CrossNetTypes)
 Gets the induced subgraph given a vector of crossnet type names. More...
 
PMMNet GetSubgraphByModeNet (TStrV &ModeNetTypes)
 Gets the induced subgraph given a vector of mode type names. More...
 
PNEANet ToNetwork (TIntV &CrossNetTypes, TIntStrStrTrV &NodeAttrMap, TVec< TTriple< TInt, TStr, TStr > > &EdgeAttrMap)
 Converts multimodal network to TNEANet; as attr names can collide, AttrMap specifies the (Mode/Cross Id, old att name, new attr name) More...
 
PNEANet ToNetwork2 (TIntV &CrossNetTypes, TIntStrPrVH &NodeAttrMap, THash< TInt, TVec< TPair< TStr, TStr > > > &EdgeAttrMap)
 Converts multimodal network to TNEANet; as attr names can collide, AttrMap specifies the Mode/Cross Id -> vec of pairs (old att name, new attr name) More...
 
PNEANetMP ToNetworkMP (TStrV &CrossNetNames)
 

Static Public Member Functions

static PMMNet Load (TSIn &SIn)
 Loads the TMMNet from binary stream. More...
 
static PMMNet LoadShM (TShMIn &ShMIn)
 Loads network from mmapped shared memory. More...
 
static PMMNet New ()
 

Public Attributes

TCRef CRef
 

Private Member Functions

void LoadNetworkShM (TShMIn &ShMIn)
 
void ClrNbr (const TInt &ModeId, const TInt &CrossNetId, const bool &outEdge, const bool &sameMode, bool &isDir)
 
int AddMode (const TStr &ModeName, const TInt &ModeId, const TModeNet &ModeNet)
 
int AddCrossNet (const TStr &CrossNetName, const TInt &CrossNetId, const TCrossNet &CrossNet)
 
int AddNodeAttributes (PNEANet &NewNet, TModeNet &Net, TVec< TPair< TStr, TStr > > &Attrs, int ModeId, int oldId, int NId)
 
int AddEdgeAttributes (PNEANet &NewNet, TCrossNet &Net, TVec< TPair< TStr, TStr > > &Attrs, int CrossId, int oldId, int EId)
 
void GetPartitionRanges (TIntPrV &Partitions, const TInt &NumPartitions, const TInt &MxVal) const
 

Private Attributes

TInt MxModeId
 
TInt MxCrossNetId
 Keeps track of the max mode id. More...
 
THash< TInt, TModeNetTModeNetH
 Keeps track of the max crossnet id. More...
 
THash< TInt, TCrossNetTCrossNetH
 
THash< TInt, TStrModeIdToNameH
 
THash< TStr, TIntModeNameToIdH
 
THash< TInt, TStrCrossIdToNameH
 
THash< TStr, TIntCrossNameToIdH
 

Friends

class TCrossNet
 
class TModeNet
 

Detailed Description

Multimodal networks.

Represents a multimodal network. A mutimodal network is represented by composing TModeNets (disjoint sets of nodes) and TCrossNets (disjoint sets of edges that connect nodes in two TModeNets). TMMNet contains methods to create TModeNets and TCrossNets by name, and returns pointers to them. All operations more granular than this, like adding nodes and edges, are run directly using methods provided in the ModeNets and CrossNets.

Definition at line 504 of file mmnet.h.

Constructor & Destructor Documentation

TMMNet::TMMNet ( )
inline

Definition at line 590 of file mmnet.h.

Referenced by Load(), LoadShM(), and New().

TInt MxModeId
Definition: mmnet.h:560
THash< TInt, TStr > ModeIdToNameH
Definition: mmnet.h:565
THash< TInt, TCrossNet > TCrossNetH
Definition: mmnet.h:563
TCRef CRef
Definition: mmnet.h:556
THash< TStr, TInt > ModeNameToIdH
Definition: mmnet.h:566
THash< TStr, TInt > CrossNameToIdH
Definition: mmnet.h:569
THash< TInt, TModeNet > TModeNetH
Keeps track of the max crossnet id.
Definition: mmnet.h:562
TInt MxCrossNetId
Keeps track of the max mode id.
Definition: mmnet.h:561
THash< TInt, TStr > CrossIdToNameH
Definition: mmnet.h:568

Here is the caller graph for this function:

TMMNet::TMMNet ( const TMMNet OtherTMMNet)
inline

Definition at line 591 of file mmnet.h.

591  : MxModeId(OtherTMMNet.MxModeId), MxCrossNetId(OtherTMMNet.MxCrossNetId), TModeNetH(OtherTMMNet.TModeNetH),
592  TCrossNetH(OtherTMMNet.TCrossNetH), ModeIdToNameH(OtherTMMNet.ModeIdToNameH), ModeNameToIdH(OtherTMMNet.ModeNameToIdH), CrossIdToNameH(OtherTMMNet.CrossIdToNameH), CrossNameToIdH(OtherTMMNet.CrossNameToIdH) {}
TInt MxModeId
Definition: mmnet.h:560
THash< TInt, TStr > ModeIdToNameH
Definition: mmnet.h:565
THash< TInt, TCrossNet > TCrossNetH
Definition: mmnet.h:563
THash< TStr, TInt > ModeNameToIdH
Definition: mmnet.h:566
THash< TStr, TInt > CrossNameToIdH
Definition: mmnet.h:569
THash< TInt, TModeNet > TModeNetH
Keeps track of the max crossnet id.
Definition: mmnet.h:562
TInt MxCrossNetId
Keeps track of the max mode id.
Definition: mmnet.h:561
THash< TInt, TStr > CrossIdToNameH
Definition: mmnet.h:568
TMMNet::TMMNet ( TSIn SIn)
inline

Definition at line 593 of file mmnet.h.

References THash< TKey, TDat, THashFunc >::BegI(), THash< TKey, TDat, THashFunc >::EndI(), THash< TKey, TDat, THashFunc >::GetDat(), TCrossNetH, and TModeNetH.

593  : MxModeId(SIn), MxCrossNetId(SIn), TModeNetH(SIn), TCrossNetH(SIn), ModeIdToNameH(SIn), ModeNameToIdH(SIn), CrossIdToNameH(SIn), CrossNameToIdH(SIn) {
594  for (THash<TInt, TModeNet>::TIter it = TModeNetH.BegI(); it < TModeNetH.EndI(); it++) {
595  it.GetDat().SetParentPointer(this);
596  }
597  for (THash<TInt, TCrossNet>::TIter it = TCrossNetH.BegI(); it < TCrossNetH.EndI(); it++) {
598  it.GetDat().SetParentPointer(this);
599  }
600  }
TInt MxModeId
Definition: mmnet.h:560
TIter BegI() const
Definition: hash.h:213
const TDat & GetDat(const TKey &Key) const
Definition: hash.h:262
TIter EndI() const
Definition: hash.h:218
THash< TInt, TStr > ModeIdToNameH
Definition: mmnet.h:565
THash< TInt, TCrossNet > TCrossNetH
Definition: mmnet.h:563
THash< TStr, TInt > ModeNameToIdH
Definition: mmnet.h:566
THash< TStr, TInt > CrossNameToIdH
Definition: mmnet.h:569
THash< TInt, TModeNet > TModeNetH
Keeps track of the max crossnet id.
Definition: mmnet.h:562
Definition: hash.h:97
TInt MxCrossNetId
Keeps track of the max mode id.
Definition: mmnet.h:561
THash< TInt, TStr > CrossIdToNameH
Definition: mmnet.h:568

Here is the call graph for this function:

Member Function Documentation

int TMMNet::AddCrossNet ( const TStr ModeName1,
const TStr ModeName2,
const TStr CrossNetName,
bool  isDir = true 
)

Adds a crossnet to the multimodal network. Specify modes by id or names; by default, crossnet is directed.

Definition at line 683 of file mmnet.cpp.

References GetModeId().

683  {
684  TInt ModeId1 = GetModeId(ModeName1);
685  TInt ModeId2 = GetModeId(ModeName2);
686  return AddCrossNet(ModeId1, ModeId2, CrossNetName, isDir);
687 }
int GetModeId(const TStr &ModeName) const
Gets the mode id from the mode name.
Definition: mmnet.h:634
int AddCrossNet(const TStr &ModeName1, const TStr &ModeName2, const TStr &CrossNetName, bool isDir=true)
Adds a crossnet to the multimodal network. Specify modes by id or names; by default, crossnet is directed.
Definition: mmnet.cpp:683
Definition: dt.h:1134

Here is the call graph for this function:

int TMMNet::AddCrossNet ( const TInt ModeId1,
const TInt ModeId2,
const TStr CrossNetName,
bool  isDir = true 
)

Definition at line 689 of file mmnet.cpp.

References THash< TKey, TDat, THashFunc >::AddDat(), TModeNet::AddNbrType(), CrossIdToNameH, CrossNameToIdH, THash< TKey, TDat, THashFunc >::GetDat(), THash< TKey, TDat, THashFunc >::IsKey(), MxCrossNetId, TCrossNet::SetParentPointer(), TCrossNet, TCrossNetH, and TModeNetH.

689  {
690  if (CrossNameToIdH.IsKey(CrossNetName)) {
691  return -1;
692  }
693  TInt CrossNetId = TInt(MxCrossNetId);
694  MxCrossNetId++;
695  CrossIdToNameH.AddDat(CrossNetId, CrossNetName);
696  CrossNameToIdH.AddDat(CrossNetName, CrossNetId);
697 
698  TCrossNet Cross = TCrossNet(ModeId1, ModeId2, isDir, CrossNetId);
699  Cross.SetParentPointer(this);
700  TCrossNetH.AddDat(CrossNetId, Cross);
701 
702  TModeNetH.GetDat(ModeId1).AddNbrType(CrossNetName, ModeId1==ModeId2, isDir);
703  TModeNetH.GetDat(ModeId2).AddNbrType(CrossNetName, ModeId1==ModeId2, isDir);
704 
705  return CrossNetId;
706 }
const TDat & GetDat(const TKey &Key) const
Definition: hash.h:262
THash< TInt, TCrossNet > TCrossNetH
Definition: mmnet.h:563
THash< TStr, TInt > CrossNameToIdH
Definition: mmnet.h:569
int AddNbrType(const TStr &CrossName, const bool sameMode, bool isDir)
Definition: mmnet.cpp:89
Definition: dt.h:1134
THash< TInt, TModeNet > TModeNetH
Keeps track of the max crossnet id.
Definition: mmnet.h:562
void SetParentPointer(TMMNet *parent)
Definition: mmnet.cpp:325
friend class TCrossNet
Definition: mmnet.h:572
bool IsKey(const TKey &Key) const
Definition: hash.h:258
TInt MxCrossNetId
Keeps track of the max mode id.
Definition: mmnet.h:561
TDat & AddDat(const TKey &Key)
Definition: hash.h:238
THash< TInt, TStr > CrossIdToNameH
Definition: mmnet.h:568
Implements a single CrossNet consisting of edges between two TModeNets (could be the same TModeNet) ...
Definition: mmnet.h:133

Here is the call graph for this function:

int TMMNet::AddCrossNet ( const TStr CrossNetName,
const TInt CrossNetId,
const TCrossNet CrossNet 
)
private

Definition at line 777 of file mmnet.cpp.

References THash< TKey, TDat, THashFunc >::AddDat(), CrossIdToNameH, CrossNameToIdH, and TCrossNetH.

777  {
778  CrossIdToNameH.AddDat(CrossNetId, CrossNetName);
779  CrossNameToIdH.AddDat(CrossNetName, CrossNetId);
780 
781  TCrossNetH.AddDat(CrossNetId, CrossNet);
782  TCrossNetH[CrossNetId].SetParentPointer(this);
783  return CrossNetId;
784 }
THash< TInt, TCrossNet > TCrossNetH
Definition: mmnet.h:563
THash< TStr, TInt > CrossNameToIdH
Definition: mmnet.h:569
TDat & AddDat(const TKey &Key)
Definition: hash.h:238
THash< TInt, TStr > CrossIdToNameH
Definition: mmnet.h:568

Here is the call graph for this function:

int TMMNet::AddEdgeAttributes ( PNEANet NewNet,
TCrossNet Net,
TVec< TPair< TStr, TStr > > &  Attrs,
int  CrossId,
int  oldId,
int  EId 
)
private

Definition at line 1341 of file mmnet.cpp.

References TCrossNet::FltType, TCrossNet::GetAttrTypeE(), TCrossNet::GetFltAttrDatE(), TCrossNet::GetIntAttrDatE(), TCrossNet::GetStrAttrDatE(), TCrossNet::IntType, and TCrossNet::StrType.

Referenced by ToNetwork2().

1341  {
1342  for (int i = 0; i < Attrs.Len(); i++) {
1343  //mode, orig attr, new attr
1344  TStr OrigAttr = Attrs[i].Val1;
1345  TStr NewAttr = Attrs[i].Val2;
1346  int type = Net.GetAttrTypeE(OrigAttr);
1347  if (type == TCrossNet::IntType) {
1348  TIntPr OldNId(CrossId, oldId);
1349  TInt Val = Net.GetIntAttrDatE(oldId, OrigAttr);
1350  NewNet->AddIntAttrDatE(EId, Val, NewAttr);
1351  } else if (type == TCrossNet::FltType) {
1352  TIntPr OldNId(CrossId, oldId);
1353  TFlt Val = Net.GetFltAttrDatE(oldId, OrigAttr);
1354  NewNet->AddFltAttrDatE(EId, Val, NewAttr);
1355  } else if (type == TCrossNet::StrType) {
1356  TIntPr OldNId(CrossId, oldId);
1357  TStr Val = Net.GetStrAttrDatE(oldId, OrigAttr);
1358  NewNet->AddStrAttrDatE(EId, Val, NewAttr);
1359  }
1360  }
1361  return 0;
1362 }
TStr GetStrAttrDatE(const TCrossEdgeI &EdgeI, const TStr &attr)
Gets the value of str attr from the edge attr value vector.
Definition: mmnet.h:417
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:575
Definition: dt.h:1383
Definition: dt.h:1134
Definition: ds.h:32
TFlt GetFltAttrDatE(const TCrossEdgeI &EdgeI, const TStr &attr)
Gets the value of flt attr from the edge attr value vector.
Definition: mmnet.h:420
Definition: dt.h:412
TInt GetIntAttrDatE(const TCrossEdgeI &EdgeI, const TStr &attr)
Gets the value of int attr from the edge attr value vector.
Definition: mmnet.h:414
int GetAttrTypeE(const TStr &attr) const
Definition: mmnet.cpp:212

Here is the call graph for this function:

Here is the caller graph for this function:

int TMMNet::AddMode ( const TStr ModeName,
const TInt ModeId,
const TModeNet ModeNet 
)
private

Definition at line 768 of file mmnet.cpp.

References THash< TKey, TDat, THashFunc >::AddDat(), ModeIdToNameH, ModeNameToIdH, and TModeNetH.

768  {
769  ModeIdToNameH.AddDat(ModeId, ModeName);
770  ModeNameToIdH.AddDat(ModeName, ModeId);
771 
772  TModeNetH.AddDat(ModeId, ModeNet);
773  TModeNetH[ModeId].SetParentPointer(this);
774  return ModeId;
775 
776 }
THash< TInt, TStr > ModeIdToNameH
Definition: mmnet.h:565
THash< TStr, TInt > ModeNameToIdH
Definition: mmnet.h:566
THash< TInt, TModeNet > TModeNetH
Keeps track of the max crossnet id.
Definition: mmnet.h:562
TDat & AddDat(const TKey &Key)
Definition: hash.h:238

Here is the call graph for this function:

int TMMNet::AddModeNet ( const TStr ModeName)

Adds a mode to the multimodal network.

Definition at line 668 of file mmnet.cpp.

References THash< TKey, TDat, THashFunc >::AddDat(), THash< TKey, TDat, THashFunc >::IsKey(), ModeIdToNameH, ModeNameToIdH, MxModeId, TModeNet::SetParentPointer(), and TModeNetH.

668  {
669  if (ModeNameToIdH.IsKey(ModeName)) {
670  return -1;
671  }
672  TInt ModeId = TInt(MxModeId);
673  MxModeId++;
674  ModeIdToNameH.AddDat(ModeId, ModeName);
675  ModeNameToIdH.AddDat(ModeName, ModeId);
676 
677  TModeNet NewGraph(ModeId);
678  NewGraph.SetParentPointer(this);
679  TModeNetH.AddDat(ModeId, NewGraph);
680  return ModeId;
681 }
TInt MxModeId
Definition: mmnet.h:560
THash< TInt, TStr > ModeIdToNameH
Definition: mmnet.h:565
THash< TStr, TInt > ModeNameToIdH
Definition: mmnet.h:566
The nodes of one particular mode in a TMMNet, and their neighbor vectors as TIntV attributes...
Definition: mmnet.h:23
Definition: dt.h:1134
THash< TInt, TModeNet > TModeNetH
Keeps track of the max crossnet id.
Definition: mmnet.h:562
bool IsKey(const TKey &Key) const
Definition: hash.h:258
TDat & AddDat(const TKey &Key)
Definition: hash.h:238

Here is the call graph for this function:

int TMMNet::AddNodeAttributes ( PNEANet NewNet,
TModeNet Net,
TVec< TPair< TStr, TStr > > &  Attrs,
int  ModeId,
int  oldId,
int  NId 
)
private

Definition at line 1314 of file mmnet.cpp.

References TNEANet::FltType, TModeNet::GetAttrTypeN(), TNEANet::GetFltAttrDatN(), TNEANet::GetIntAttrDatN(), TNEANet::GetIntVAttrDatN(), TNEANet::GetStrAttrDatN(), TNEANet::IntType, TNEANet::IntVType, and TNEANet::StrType.

Referenced by ToNetwork2().

1314  {
1315  for (int i = 0; i < Attrs.Len(); i++) {
1316  //mode, orig attr, new attr
1317  TStr OrigAttr = Attrs[i].Val1;
1318  TStr NewAttr = Attrs[i].Val2;
1319  int type = Net.GetAttrTypeN(OrigAttr);
1320  if (type == TModeNet::IntType) {
1321  TIntPr OldNId(ModeId, oldId);
1322  TInt Val = Net.GetIntAttrDatN(oldId, OrigAttr);
1323  NewNet->AddIntAttrDatN(NId, Val, NewAttr);
1324  } else if (type == TModeNet::FltType) {
1325  TIntPr OldNId(ModeId, oldId);
1326  TFlt Val = Net.GetFltAttrDatN(oldId, OrigAttr);
1327  NewNet->AddFltAttrDatN(NId, Val, NewAttr);
1328  } else if (type == TModeNet::StrType) {
1329  TIntPr OldNId(ModeId, oldId);
1330  TStr Val = Net.GetStrAttrDatN(oldId, OrigAttr);
1331  NewNet->AddStrAttrDatN(NId, Val, NewAttr);
1332  } else if (type == TModeNet::IntVType) {
1333  TIntPr OldNId(ModeId, oldId);
1334  TIntV Val = Net.GetIntVAttrDatN(oldId, OrigAttr);
1335  NewNet->AddIntVAttrDatN(NId, Val, NewAttr);
1336  }
1337  }
1338  return 0;
1339 }
TInt GetIntAttrDatN(const TNodeI &NodeI, const TStr &attr)
Gets the value of int attr from the node attr value vector.
Definition: network.h:2701
TStr GetStrAttrDatN(const TNodeI &NodeI, const TStr &attr)
Gets the value of str attr from the node attr value vector.
Definition: network.h:2705
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:575
TIntV GetIntVAttrDatN(const TNodeI &NodeI, const TStr &attr) const
Gets the value of the intv attr from the node attr value vector.
Definition: network.h:2711
Definition: dt.h:1383
TFlt GetFltAttrDatN(const TNodeI &NodeI, const TStr &attr)
Gets the value of flt attr from the node attr value vector.
Definition: network.h:2708
Definition: dt.h:1134
Definition: ds.h:32
Definition: dt.h:412
int GetAttrTypeN(const TStr &attr) const
Definition: mmnet.cpp:204

Here is the call graph for this function:

Here is the caller graph for this function:

TCrossNetI TMMNet::BegCrossNetI ( ) const
inline

Definition at line 652 of file mmnet.h.

References THash< TKey, TDat, THashFunc >::BegI(), and TCrossNetH.

652 { return TCrossNetI(TCrossNetH.BegI(), this); }
TIter BegI() const
Definition: hash.h:213
THash< TInt, TCrossNet > TCrossNetH
Definition: mmnet.h:563

Here is the call graph for this function:

TModeNetI TMMNet::BegModeNetI ( ) const
inline

Definition at line 657 of file mmnet.h.

References THash< TKey, TDat, THashFunc >::BegI(), and TModeNetH.

657 { return TModeNetI(TModeNetH.BegI(), this); }
TIter BegI() const
Definition: hash.h:213
THash< TInt, TModeNet > TModeNetH
Keeps track of the max crossnet id.
Definition: mmnet.h:562

Here is the call graph for this function:

void TMMNet::ClrNbr ( const TInt ModeId,
const TInt CrossNetId,
const bool &  outEdge,
const bool &  sameMode,
bool &  isDir 
)
private

Definition at line 786 of file mmnet.cpp.

References CrossIdToNameH, and TModeNetH.

Referenced by TCrossNet::Clr().

786  {
787  TStr CrossNetName = CrossIdToNameH[CrossNetId];
788  TModeNetH[ModeId].ClrNbr(CrossNetName, outEdge, sameMode, isDir);
789 }
THash< TInt, TModeNet > TModeNetH
Keeps track of the max crossnet id.
Definition: mmnet.h:562
Definition: dt.h:412
THash< TInt, TStr > CrossIdToNameH
Definition: mmnet.h:568

Here is the caller graph for this function:

void TMMNet::ConvertToSparse ( )
inline

Definition at line 627 of file mmnet.h.

References THash< TKey, TDat, THashFunc >::BegI(), THash< TKey, TDat, THashFunc >::EndI(), and TModeNetH.

627  {
628  for (THash<TInt, TModeNet>::TIter it = TModeNetH.BegI(); it < TModeNetH.EndI(); it++) {
629  it.GetDat().ConvertToSparse();
630  }
631  }
TIter BegI() const
Definition: hash.h:213
TIter EndI() const
Definition: hash.h:218
THash< TInt, TModeNet > TModeNetH
Keeps track of the max crossnet id.
Definition: mmnet.h:562
Definition: hash.h:97

Here is the call graph for this function:

int TMMNet::DelCrossNet ( const TInt CrossNetId)

Deletes a crossnet from the multimodal network.

Definition at line 708 of file mmnet.cpp.

References CrossIdToNameH, and THash< TKey, TDat, THashFunc >::GetDat().

Referenced by DelModeNet().

708  {
709  return DelCrossNet(CrossIdToNameH.GetDat(CrossNetId));
710 }
int DelCrossNet(const TInt &CrossNetId)
Deletes a crossnet from the multimodal network.
Definition: mmnet.cpp:708
const TDat & GetDat(const TKey &Key) const
Definition: hash.h:262
THash< TInt, TStr > CrossIdToNameH
Definition: mmnet.h:568

Here is the call graph for this function:

Here is the caller graph for this function:

int TMMNet::DelCrossNet ( const TStr CrossNet)

Definition at line 712 of file mmnet.cpp.

References CrossIdToNameH, CrossNameToIdH, TStr::CStr(), THash< TKey, TDat, THashFunc >::DelKey(), TStr::Fmt(), GetCrossNetById(), THash< TKey, TDat, THashFunc >::GetDat(), GetModeNetById(), IAssertR, THash< TKey, TDat, THashFunc >::IsKey(), TCrossNet::Mode1, TCrossNet::Mode2, TCrossNet::SetParentPointer(), and TCrossNetH.

712  {
713  IAssertR(CrossNameToIdH.IsKey(CrossNet),TStr::Fmt("No such link type: %s", CrossNet.CStr()));
714  TInt CrossNetId = CrossNameToIdH.GetDat(CrossNet);
715  TInt Mode1 = GetCrossNetById(CrossNetId).Mode1;
716  TInt Mode2 = GetCrossNetById(CrossNetId).Mode2;
717  if (GetModeNetById(Mode1).DelNbrType(CrossNet) == -1 || (Mode1 != Mode2 && GetModeNetById(Mode2).DelNbrType(CrossNet) == -1)) {
718  return -1;
719  }
720  CrossNameToIdH.DelKey(CrossNet);
721  CrossIdToNameH.DelKey(CrossNetId);
722  GetCrossNetById(CrossNetId).SetParentPointer(NULL);
723  TCrossNetH.DelKey(CrossNetId);
724  return 0;
725 }
#define IAssertR(Cond, Reason)
Definition: bd.h:265
const TDat & GetDat(const TKey &Key) const
Definition: hash.h:262
THash< TInt, TCrossNet > TCrossNetH
Definition: mmnet.h:563
void DelKey(const TKey &Key)
Definition: hash.h:404
THash< TStr, TInt > CrossNameToIdH
Definition: mmnet.h:569
Definition: dt.h:1134
void SetParentPointer(TMMNet *parent)
Definition: mmnet.cpp:325
TModeNet & GetModeNetById(const TInt &ModeId) const
Definition: mmnet.cpp:753
static TStr Fmt(const char *FmtStr,...)
Definition: dt.cpp:1599
TInt Mode1
Definition: mmnet.h:266
TInt Mode2
The first mode. In the case of directed crossnets, this is implicitly understood to be the source mod...
Definition: mmnet.h:267
char * CStr()
Definition: dt.h:476
bool IsKey(const TKey &Key) const
Definition: hash.h:258
TCrossNet & GetCrossNetById(const TInt &CrossId) const
Definition: mmnet.cpp:762
THash< TInt, TStr > CrossIdToNameH
Definition: mmnet.h:568

Here is the call graph for this function:

int TMMNet::DelModeNet ( const TInt ModeId)

Deletes a mode from the multimodal network.

Definition at line 727 of file mmnet.cpp.

References DelCrossNet(), THash< TKey, TDat, THashFunc >::DelKey(), TModeNet::GetCrossNetNames(), THash< TKey, TDat, THashFunc >::GetDat(), GetModeNetById(), TVec< TVal, TSizeTy >::Len(), ModeIdToNameH, ModeNameToIdH, TModeNet::SetParentPointer(), and TModeNetH.

Referenced by DelModeNet().

727  {
728  TStrV CrossNets;
729  GetModeNetById(ModeId).GetCrossNetNames(CrossNets);
730  for (int i = 0; i < CrossNets.Len(); i++) {
731  if (DelCrossNet(CrossNets[i]) == -1) {
732  return -1;
733  }
734  }
735  TStr ModeName = ModeIdToNameH.GetDat(ModeId);
736  ModeNameToIdH.DelKey(ModeName);
737  ModeIdToNameH.DelKey(ModeId);
738  GetModeNetById(ModeId).SetParentPointer(NULL);
739  TModeNetH.DelKey(ModeId);
740  return 0;
741 }
int DelCrossNet(const TInt &CrossNetId)
Deletes a crossnet from the multimodal network.
Definition: mmnet.cpp:708
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:575
const TDat & GetDat(const TKey &Key) const
Definition: hash.h:262
THash< TInt, TStr > ModeIdToNameH
Definition: mmnet.h:565
void DelKey(const TKey &Key)
Definition: hash.h:404
THash< TStr, TInt > ModeNameToIdH
Definition: mmnet.h:566
void GetCrossNetNames(TStrV &Names) const
Gets a list of CrossNets that have this Mode as either a source or destination type.
Definition: mmnet.h:77
THash< TInt, TModeNet > TModeNetH
Keeps track of the max crossnet id.
Definition: mmnet.h:562
TModeNet & GetModeNetById(const TInt &ModeId) const
Definition: mmnet.cpp:753
Definition: dt.h:412
void SetParentPointer(TMMNet *parent)
Definition: mmnet.cpp:85

Here is the call graph for this function:

Here is the caller graph for this function:

int TMMNet::DelModeNet ( const TStr ModeName)

Definition at line 743 of file mmnet.cpp.

References TStr::CStr(), DelModeNet(), TStr::Fmt(), THash< TKey, TDat, THashFunc >::GetDat(), IAssertR, THash< TKey, TDat, THashFunc >::IsKey(), and ModeNameToIdH.

743  {
744  IAssertR(ModeNameToIdH.IsKey(ModeName), TStr::Fmt("No such mode with name: %s", ModeName.CStr()));
745  return DelModeNet(ModeNameToIdH.GetDat(ModeName));
746 }
#define IAssertR(Cond, Reason)
Definition: bd.h:265
const TDat & GetDat(const TKey &Key) const
Definition: hash.h:262
int DelModeNet(const TInt &ModeId)
Deletes a mode from the multimodal network.
Definition: mmnet.cpp:727
THash< TStr, TInt > ModeNameToIdH
Definition: mmnet.h:566
static TStr Fmt(const char *FmtStr,...)
Definition: dt.cpp:1599
char * CStr()
Definition: dt.h:476
bool IsKey(const TKey &Key) const
Definition: hash.h:258

Here is the call graph for this function:

TCrossNetI TMMNet::EndCrossNetI ( ) const
inline

Definition at line 653 of file mmnet.h.

References THash< TKey, TDat, THashFunc >::EndI(), and TCrossNetH.

653 { return TCrossNetI(TCrossNetH.EndI(), this); }
TIter EndI() const
Definition: hash.h:218
THash< TInt, TCrossNet > TCrossNetH
Definition: mmnet.h:563

Here is the call graph for this function:

TModeNetI TMMNet::EndModeNetI ( ) const
inline

Definition at line 658 of file mmnet.h.

References THash< TKey, TDat, THashFunc >::EndI(), and TModeNetH.

658 { return TModeNetI(TModeNetH.EndI(), this); }
TIter EndI() const
Definition: hash.h:218
THash< TInt, TModeNet > TModeNetH
Keeps track of the max crossnet id.
Definition: mmnet.h:562

Here is the call graph for this function:

int TMMNet::GetCrossId ( const TStr CrossName) const
inline

Gets the crossnet id from the crossnet name.

Definition at line 638 of file mmnet.h.

References CrossNameToIdH, THash< TKey, TDat, THashFunc >::GetDat(), and THash< TKey, TDat, THashFunc >::IsKey().

Referenced by ToNetworkMP().

638 { if (CrossNameToIdH.IsKey(CrossName)) { return CrossNameToIdH.GetDat(CrossName); } else { return -1; } }
const TDat & GetDat(const TKey &Key) const
Definition: hash.h:262
THash< TStr, TInt > CrossNameToIdH
Definition: mmnet.h:569
bool IsKey(const TKey &Key) const
Definition: hash.h:258

Here is the call graph for this function:

Here is the caller graph for this function:

TStr TMMNet::GetCrossName ( const TInt CrossId) const
inline

Gets the crossnet name from the crossnet id.

Definition at line 640 of file mmnet.h.

References CrossIdToNameH, THash< TKey, TDat, THashFunc >::GetDat(), TStr::GetNullStr(), and THash< TKey, TDat, THashFunc >::IsKey().

Referenced by TCrossNet::AddEdge(), TModeNet::AddNeighbor(), TCrossNet::DelEdge(), TModeNet::DelNeighbor(), and TMMNet::TCrossNetI::GetCrossName().

640 { if (CrossIdToNameH.IsKey(CrossId)) { return CrossIdToNameH.GetDat(CrossId); } else { return TStr::GetNullStr(); } }
const TDat & GetDat(const TKey &Key) const
Definition: hash.h:262
static TStr GetNullStr()
Definition: dt.cpp:1626
bool IsKey(const TKey &Key) const
Definition: hash.h:258
THash< TInt, TStr > CrossIdToNameH
Definition: mmnet.h:568

Here is the call graph for this function:

Here is the caller graph for this function:

TCrossNet & TMMNet::GetCrossNetById ( const TInt CrossId) const

Definition at line 762 of file mmnet.cpp.

Referenced by DelCrossNet(), TMMNet::TCrossNetI::GetCrossNet(), GetCrossNetByName(), ToNetwork(), and ToNetwork2().

762  {
763  //IAssertR(CrossIdToNameH.IsKey(CrossId),TStr::Fmt("No link with id %d exists", CrossId));
764  TCrossNet& CrossNet = (const_cast<TMMNet *>(this))->TCrossNetH.GetDat(CrossId);
765  return CrossNet;
766 }
Multimodal networks.
Definition: mmnet.h:504
Implements a single CrossNet consisting of edges between two TModeNets (could be the same TModeNet) ...
Definition: mmnet.h:133

Here is the caller graph for this function:

TCrossNet & TMMNet::GetCrossNetByName ( const TStr CrossName) const

Gets a reference to the crossnet.

Definition at line 758 of file mmnet.cpp.

References CrossNameToIdH, GetCrossNetById(), and THash< TKey, TDat, THashFunc >::GetDat().

Referenced by TModeNet::Clr(), TModeNet::DelNode(), and ToNetworkMP().

758  {
759  //IAssertR(CrossNameToIdH.IsKey(CrossName),TStr::Fmt("No such link name: %s", CrossName.CStr()));
760  return GetCrossNetById(CrossNameToIdH.GetDat(CrossName));
761 }
const TDat & GetDat(const TKey &Key) const
Definition: hash.h:262
THash< TStr, TInt > CrossNameToIdH
Definition: mmnet.h:569
TCrossNet & GetCrossNetById(const TInt &CrossId) const
Definition: mmnet.cpp:762

Here is the call graph for this function:

Here is the caller graph for this function:

TCrossNetI TMMNet::GetCrossNetI ( const int &  Id) const
inline

Iterator over all crossnets.

Definition at line 651 of file mmnet.h.

References THash< TKey, TDat, THashFunc >::GetI(), and TCrossNetH.

651 { return TCrossNetI(TCrossNetH.GetI(Id), this); }
THash< TInt, TCrossNet > TCrossNetH
Definition: mmnet.h:563
TIter GetI(const TKey &Key) const
Definition: hash.h:220

Here is the call graph for this function:

int TMMNet::GetCrossNets ( )
inline

Returns the number of crossnets in the multimodal network.

Definition at line 663 of file mmnet.h.

References THash< TKey, TDat, THashFunc >::Len(), and TCrossNetH.

663 { return TCrossNetH.Len(); }
THash< TInt, TCrossNet > TCrossNetH
Definition: mmnet.h:563
int Len() const
Definition: hash.h:228

Here is the call graph for this function:

int TMMNet::GetModeId ( const TStr ModeName) const
inline

Gets the mode id from the mode name.

Definition at line 634 of file mmnet.h.

References THash< TKey, TDat, THashFunc >::GetDat(), THash< TKey, TDat, THashFunc >::IsKey(), and ModeNameToIdH.

Referenced by AddCrossNet().

634 { if (ModeNameToIdH.IsKey(ModeName)) { return ModeNameToIdH.GetDat(ModeName); } else { return -1; } }
const TDat & GetDat(const TKey &Key) const
Definition: hash.h:262
THash< TStr, TInt > ModeNameToIdH
Definition: mmnet.h:566
bool IsKey(const TKey &Key) const
Definition: hash.h:258

Here is the call graph for this function:

Here is the caller graph for this function:

TStr TMMNet::GetModeName ( const TInt ModeId) const
inline

Gets the mode name from the mode id.

Definition at line 636 of file mmnet.h.

References THash< TKey, TDat, THashFunc >::GetDat(), TStr::GetNullStr(), THash< TKey, TDat, THashFunc >::IsKey(), and ModeIdToNameH.

Referenced by TMMNet::TModeNetI::GetModeName().

636 { if (ModeIdToNameH.IsKey(ModeId)) { return ModeIdToNameH.GetDat(ModeId); } else {return TStr::GetNullStr();} }
const TDat & GetDat(const TKey &Key) const
Definition: hash.h:262
THash< TInt, TStr > ModeIdToNameH
Definition: mmnet.h:565
static TStr GetNullStr()
Definition: dt.cpp:1626
bool IsKey(const TKey &Key) const
Definition: hash.h:258

Here is the call graph for this function:

Here is the caller graph for this function:

TModeNet & TMMNet::GetModeNetById ( const TInt ModeId) const

Definition at line 753 of file mmnet.cpp.

Referenced by DelCrossNet(), TCrossNet::DelEdge(), DelModeNet(), TMMNet::TModeNetI::GetModeNet(), GetModeNetByName(), ToNetwork(), ToNetwork2(), and ToNetworkMP().

753  {
754 // IAssertR(ModeId < TModeNetH.Len(), TStr::Fmt("Mode with id %d does not exist", ModeId));
755  TModeNet &Net = (const_cast<TMMNet *>(this))->TModeNetH.GetDat(ModeId);
756  return Net;
757 }
The nodes of one particular mode in a TMMNet, and their neighbor vectors as TIntV attributes...
Definition: mmnet.h:23
Multimodal networks.
Definition: mmnet.h:504

Here is the caller graph for this function:

TModeNet & TMMNet::GetModeNetByName ( const TStr ModeName) const

Gets a reference to the modenet.

Definition at line 748 of file mmnet.cpp.

References THash< TKey, TDat, THashFunc >::GetDat(), GetModeNetById(), and ModeNameToIdH.

748  {
749  //IAssertR(ModeNameToIdH.IsKey(ModeName),TStr::Fmt("No such mode name: %s", ModeName.CStr()));
750  return GetModeNetById(ModeNameToIdH.GetDat(ModeName));
751 }
const TDat & GetDat(const TKey &Key) const
Definition: hash.h:262
THash< TStr, TInt > ModeNameToIdH
Definition: mmnet.h:566
TModeNet & GetModeNetById(const TInt &ModeId) const
Definition: mmnet.cpp:753

Here is the call graph for this function:

TModeNetI TMMNet::GetModeNetI ( const int &  Id) const
inline

Iterator over all modenets.

Definition at line 656 of file mmnet.h.

References THash< TKey, TDat, THashFunc >::GetI(), and TModeNetH.

656 { return TModeNetI(TModeNetH.GetI(Id), this); }
THash< TInt, TModeNet > TModeNetH
Keeps track of the max crossnet id.
Definition: mmnet.h:562
TIter GetI(const TKey &Key) const
Definition: hash.h:220

Here is the call graph for this function:

int TMMNet::GetModeNets ( )
inline

Returns the number of modes in the multimodal network.

Definition at line 661 of file mmnet.h.

References THash< TKey, TDat, THashFunc >::Len(), and TModeNetH.

661 { return TModeNetH.Len(); }
THash< TInt, TModeNet > TModeNetH
Keeps track of the max crossnet id.
Definition: mmnet.h:562
int Len() const
Definition: hash.h:228

Here is the call graph for this function:

void TMMNet::GetPartitionRanges ( TIntPrV Partitions,
const TInt NumPartitions,
const TInt MxVal 
) const
private

Definition at line 1115 of file mmnet.cpp.

References TVec< TVal, TSizeTy >::Add().

Referenced by ToNetworkMP().

1115  {
1116  if (MxLen <= NumPartitions) {
1117  Partitions.Add(TIntPr(0,MxLen));
1118  } else {
1119  TInt PartitionSize = MxLen/NumPartitions;
1120  TInt CurrStart = 0;
1121  bool done = false;
1122  while (!done) {
1123  TInt CurrEnd = CurrStart + PartitionSize;
1124  if (MxLen - CurrEnd < PartitionSize) {
1125  CurrEnd = MxLen;
1126  done = true;
1127  }
1128  Partitions.Add(TIntPr(CurrStart, CurrEnd));
1129  CurrStart = CurrEnd;
1130  }
1131  }
1132 }
TPair< TInt, TInt > TIntPr
Definition: ds.h:83
Definition: dt.h:1134
TSizeTy Add()
Adds a new element at the end of the vector, after its current last element.
Definition: ds.h:602

Here is the call graph for this function:

Here is the caller graph for this function:

PMMNet TMMNet::GetSubgraphByCrossNet ( TStrV CrossNetTypes)

Gets the induced subgraph given a vector of crossnet type names.

Definition at line 791 of file mmnet.cpp.

References THash< TKey, TDat, THashFunc >::AddDat(), THash< TKey, TDat, THashFunc >::BegI(), CrossNameToIdH, THash< TKey, TDat, THashFunc >::EndI(), THash< TKey, TDat, THashFunc >::GetDat(), THash< TKey, TDat, THashFunc >::IsKey(), TVec< TVal, TSizeTy >::Len(), TModeNet::ModeId, ModeIdToNameH, New(), TCrossNetH, and TModeNetH.

Referenced by GetSubgraphByModeNet().

791  {
792  PMMNet Result = New();
793  TInt MxMode = 0;
794  TInt MxCross = 0;
795  TIntH ModeH;
796  for(int i = 0; i < CrossNetTypes.Len(); i++) {
797  TStr CrossName = CrossNetTypes[i];
798  TInt OldId = CrossNameToIdH.GetDat(CrossName);
799  TInt NewId = MxCross++;
800  TCrossNet NewCrossNet(TCrossNetH.GetDat(OldId));
801  TInt OldModeId1 = NewCrossNet.Mode1;
802  TInt OldModeId2 = NewCrossNet.Mode2;
803  TInt NewModeId1, NewModeId2;
804  if (ModeH.IsKey(OldModeId1)) {
805  NewModeId1 = ModeH.GetDat(OldModeId1);
806  } else {
807  NewModeId1 = MxMode++;
808  ModeH.AddDat(OldModeId1, NewModeId1);
809  }
810  if (ModeH.IsKey(OldModeId2)) {
811  NewModeId2 = ModeH.GetDat(OldModeId2);
812  } else {
813  NewModeId2 = MxMode++;
814  ModeH.AddDat(OldModeId2, NewModeId2);
815  }
816  NewCrossNet.Mode1 = NewModeId1;
817  NewCrossNet.Mode2 = NewModeId2;
818  NewCrossNet.CrossNetId = NewId;
819  Result->AddCrossNet(CrossName, NewId, NewCrossNet);
820  }
821  for(TIntH::TIter it = ModeH.BegI(); it < ModeH.EndI(); it++) {
822  TStr ModeName = ModeIdToNameH.GetDat(it.GetKey());
823  TInt NewModeId = it.GetDat();
824  TModeNet NewModeNet;
825  TModeNetH.GetDat(it.GetKey()).RemoveCrossNets(NewModeNet, CrossNetTypes);
826  NewModeNet.ModeId = NewModeId;
827  Result->AddMode(ModeName, NewModeId, NewModeNet);
828  }
829  Result->MxModeId = MxMode;
830  Result->MxCrossNetId = MxCross;
831  return Result;
832 }
TIter BegI() const
Definition: hash.h:213
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:575
const TDat & GetDat(const TKey &Key) const
Definition: hash.h:262
TIter EndI() const
Definition: hash.h:218
THash< TInt, TStr > ModeIdToNameH
Definition: mmnet.h:565
THash< TInt, TCrossNet > TCrossNetH
Definition: mmnet.h:563
TInt ModeId
Definition: mmnet.h:46
THash< TStr, TInt > CrossNameToIdH
Definition: mmnet.h:569
The nodes of one particular mode in a TMMNet, and their neighbor vectors as TIntV attributes...
Definition: mmnet.h:23
Definition: dt.h:1134
THash< TInt, TModeNet > TModeNetH
Keeps track of the max crossnet id.
Definition: mmnet.h:562
static PMMNet New()
Definition: mmnet.h:625
Definition: dt.h:412
Definition: bd.h:196
bool IsKey(const TKey &Key) const
Definition: hash.h:258
TDat & AddDat(const TKey &Key)
Definition: hash.h:238
Implements a single CrossNet consisting of edges between two TModeNets (could be the same TModeNet) ...
Definition: mmnet.h:133

Here is the call graph for this function:

Here is the caller graph for this function:

PMMNet TMMNet::GetSubgraphByModeNet ( TStrV ModeNetTypes)

Gets the induced subgraph given a vector of mode type names.

Definition at line 834 of file mmnet.cpp.

References TVec< TVal, TSizeTy >::Add(), THash< TKey, TDat, THashFunc >::AddDat(), THash< TKey, TDat, THashFunc >::BegI(), CrossIdToNameH, THash< TKey, TDat, THashFunc >::EndI(), THash< TKey, TDat, THashFunc >::GetDat(), GetSubgraphByCrossNet(), THash< TKey, TDat, THashFunc >::IsKey(), TVec< TVal, TSizeTy >::Len(), TCrossNet::Mode1, TCrossNet::Mode2, TModeNet::ModeId, ModeIdToNameH, ModeNameToIdH, TCrossNetH, and TModeNetH.

834  {
835  THash<TInt, TBool> ModeTypeIds;
836  for (int i = 0; i < ModeNetTypes.Len(); i++) {
837  ModeTypeIds.AddDat(ModeNameToIdH.GetDat(ModeNetTypes[i]), true);
838  }
839  TStrV CrossNetTypes;
840  for (THash<TInt, TCrossNet>::TIter it = TCrossNetH.BegI(); it < TCrossNetH.EndI(); it++) {
841  TCrossNet& CrossNet = it.GetDat();
842  if (ModeTypeIds.IsKey(CrossNet.Mode1) && ModeTypeIds.IsKey(CrossNet.Mode2)) {
843  CrossNetTypes.Add(CrossIdToNameH.GetDat(it.GetKey()));
844  ModeTypeIds[CrossNet.Mode1] = false;
845  ModeTypeIds[CrossNet.Mode2] = false;
846  }
847  }
848 
849  PMMNet Result = GetSubgraphByCrossNet(CrossNetTypes);
850  TInt MxMode = Result->MxModeId;
851  TStrV EmptyCrossNetTypes;
852  for (THash<TInt, TBool>::TIter it = ModeTypeIds.BegI(); it < ModeTypeIds.EndI(); it++) {
853  if (it.GetDat().Val) {
854  TStr ModeName = ModeIdToNameH.GetDat(it.GetKey());
855  TInt NewModeId = MxMode++;
856  TModeNet NewModeNet;
857  TModeNetH.GetDat(it.GetKey()).RemoveCrossNets(NewModeNet, EmptyCrossNetTypes);
858  NewModeNet.ModeId = NewModeId;
859  Result->AddMode(ModeName, NewModeId, NewModeNet);
860  }
861  }
862  Result->MxModeId = MxMode;
863  return Result;
864 }
PMMNet GetSubgraphByCrossNet(TStrV &CrossNetTypes)
Gets the induced subgraph given a vector of crossnet type names.
Definition: mmnet.cpp:791
TIter BegI() const
Definition: hash.h:213
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:575
const TDat & GetDat(const TKey &Key) const
Definition: hash.h:262
TIter EndI() const
Definition: hash.h:218
THash< TInt, TStr > ModeIdToNameH
Definition: mmnet.h:565
THash< TInt, TCrossNet > TCrossNetH
Definition: mmnet.h:563
THash< TStr, TInt > ModeNameToIdH
Definition: mmnet.h:566
TInt ModeId
Definition: mmnet.h:46
The nodes of one particular mode in a TMMNet, and their neighbor vectors as TIntV attributes...
Definition: mmnet.h:23
Definition: dt.h:1134
THash< TInt, TModeNet > TModeNetH
Keeps track of the max crossnet id.
Definition: mmnet.h:562
Definition: dt.h:412
Definition: hash.h:97
TInt Mode1
Definition: mmnet.h:266
TInt Mode2
The first mode. In the case of directed crossnets, this is implicitly understood to be the source mod...
Definition: mmnet.h:267
Definition: bd.h:196
bool IsKey(const TKey &Key) const
Definition: hash.h:258
TSizeTy Add()
Adds a new element at the end of the vector, after its current last element.
Definition: ds.h:602
TDat & AddDat(const TKey &Key)
Definition: hash.h:238
THash< TInt, TStr > CrossIdToNameH
Definition: mmnet.h:568
Implements a single CrossNet consisting of edges between two TModeNets (could be the same TModeNet) ...
Definition: mmnet.h:133

Here is the call graph for this function:

static PMMNet TMMNet::Load ( TSIn SIn)
inlinestatic

Loads the TMMNet from binary stream.

Definition at line 618 of file mmnet.h.

References TMMNet().

618 { return PMMNet(new TMMNet(SIn)); }
TMMNet()
Definition: mmnet.h:590
TPt< TMMNet > PMMNet
Definition: mmnet.h:5

Here is the call graph for this function:

void TMMNet::LoadNetworkShM ( TShMIn ShMIn)
private

Definition at line 649 of file mmnet.cpp.

References THash< TKey, TDat, THashFunc >::BegI(), CrossIdToNameH, CrossNameToIdH, THash< TKey, TDat, THashFunc >::EndI(), THash< TKey, TDat, THashFunc >::LoadShM(), ModeIdToNameH, ModeNameToIdH, MxCrossNetId, MxModeId, TCrossNetH, and TModeNetH.

Referenced by LoadShM().

649  {
650  MxModeId = TInt(ShMIn);
651  MxCrossNetId = TInt(ShMIn);
652  TModeNetInit Fm;
653  TModeNetH.LoadShM(ShMIn, Fm);
654  TCrossNetInit Fc;
655  TCrossNetH.LoadShM(ShMIn, Fc);
656  ModeIdToNameH.LoadShM(ShMIn);
657  ModeNameToIdH.LoadShM(ShMIn);
658  CrossIdToNameH.LoadShM(ShMIn);
659  CrossNameToIdH.LoadShM(ShMIn);
660  for (THash<TInt, TModeNet>::TIter it = TModeNetH.BegI(); it < TModeNetH.EndI(); it++) {
661  it.GetDat().SetParentPointer(this);
662  }
663  for (THash<TInt, TCrossNet>::TIter it = TCrossNetH.BegI(); it < TCrossNetH.EndI(); it++) {
664  it.GetDat().SetParentPointer(this);
665  }
666 }
TInt MxModeId
Definition: mmnet.h:560
TIter BegI() const
Definition: hash.h:213
TIter EndI() const
Definition: hash.h:218
THash< TInt, TStr > ModeIdToNameH
Definition: mmnet.h:565
THash< TInt, TCrossNet > TCrossNetH
Definition: mmnet.h:563
void LoadShM(TShMIn &ShMIn)
Load THash from shared memory file. Copying/Deleting Keys is illegal.
Definition: hash.h:157
THash< TStr, TInt > ModeNameToIdH
Definition: mmnet.h:566
THash< TStr, TInt > CrossNameToIdH
Definition: mmnet.h:569
Definition: dt.h:1134
THash< TInt, TModeNet > TModeNetH
Keeps track of the max crossnet id.
Definition: mmnet.h:562
Definition: hash.h:97
TInt MxCrossNetId
Keeps track of the max mode id.
Definition: mmnet.h:561
THash< TInt, TStr > CrossIdToNameH
Definition: mmnet.h:568

Here is the call graph for this function:

Here is the caller graph for this function:

static PMMNet TMMNet::LoadShM ( TShMIn ShMIn)
inlinestatic

Loads network from mmapped shared memory.

Definition at line 620 of file mmnet.h.

References LoadNetworkShM(), and TMMNet().

620  {
621  TMMNet* Network = new TMMNet();
622  Network->LoadNetworkShM(ShMIn);
623  return PMMNet(Network);
624  }
void LoadNetworkShM(TShMIn &ShMIn)
Definition: mmnet.cpp:649
TMMNet()
Definition: mmnet.h:590
TPt< TMMNet > PMMNet
Definition: mmnet.h:5
Multimodal networks.
Definition: mmnet.h:504

Here is the call graph for this function:

static PMMNet TMMNet::New ( )
inlinestatic

Definition at line 625 of file mmnet.h.

References TMMNet().

Referenced by GetSubgraphByCrossNet().

625 { return PMMNet(new TMMNet()); }
TMMNet()
Definition: mmnet.h:590
TPt< TMMNet > PMMNet
Definition: mmnet.h:5

Here is the call graph for this function:

Here is the caller graph for this function:

void TMMNet::Save ( TSOut SOut) const
inline

Saves the TMMNet to binary stream.

Definition at line 614 of file mmnet.h.

References CrossIdToNameH, CrossNameToIdH, ModeIdToNameH, ModeNameToIdH, MxCrossNetId, MxModeId, THash< TKey, TDat, THashFunc >::Save(), TInt::Save(), TCrossNetH, and TModeNetH.

614  {MxModeId.Save(SOut); MxCrossNetId.Save(SOut); TModeNetH.Save(SOut);
616  CrossNameToIdH.Save(SOut); }
TInt MxModeId
Definition: mmnet.h:560
void Save(TSOut &SOut) const
Definition: dt.h:1150
void Save(TSOut &SOut) const
Definition: hash.h:183
THash< TInt, TStr > ModeIdToNameH
Definition: mmnet.h:565
THash< TInt, TCrossNet > TCrossNetH
Definition: mmnet.h:563
THash< TStr, TInt > ModeNameToIdH
Definition: mmnet.h:566
THash< TStr, TInt > CrossNameToIdH
Definition: mmnet.h:569
THash< TInt, TModeNet > TModeNetH
Keeps track of the max crossnet id.
Definition: mmnet.h:562
TInt MxCrossNetId
Keeps track of the max mode id.
Definition: mmnet.h:561
THash< TInt, TStr > CrossIdToNameH
Definition: mmnet.h:568

Here is the call graph for this function:

PNEANet TMMNet::ToNetwork ( TIntV CrossNetTypes,
TIntStrStrTrV NodeAttrMap,
TVec< TTriple< TInt, TStr, TStr > > &  EdgeAttrMap 
)

Converts multimodal network to TNEANet; as attr names can collide, AttrMap specifies the (Mode/Cross Id, old att name, new attr name)

Definition at line 866 of file mmnet.cpp.

References THash< TKey, TDat, THashFunc >::AddDat(), THashSet< TKey, THashFunc >::AddKey(), TCrossNet::BegEdgeI(), THash< TKey, TDat, THashFunc >::BegI(), THashSet< TKey, THashFunc >::BegI(), TModeNet::BegMMNI(), TCrossNet::EndEdgeI(), THash< TKey, TDat, THashFunc >::EndI(), THashSet< TKey, THashFunc >::EndI(), TModeNet::EndMMNI(), TCrossNet::FltType, TNEANet::FltType, TCrossNet::GetAttrTypeE(), TModeNet::GetAttrTypeN(), GetCrossNetById(), THash< TKey, TDat, THashFunc >::GetDat(), TCrossNet::GetFltAttrDatE(), TNEANet::GetFltAttrDatN(), TCrossNet::GetFltAttrDefaultE(), TNEANet::GetFltAttrDefaultN(), TCrossNet::GetIntAttrDatE(), TNEANet::GetIntAttrDatN(), TCrossNet::GetIntAttrDefaultE(), TNEANet::GetIntAttrDefaultN(), TNEANet::GetIntVAttrDatN(), TCrossNet::GetMode1(), TCrossNet::GetMode2(), GetModeNetById(), TCrossNet::GetStrAttrDatE(), TNEANet::GetStrAttrDatN(), TCrossNet::GetStrAttrDefaultE(), TNEANet::GetStrAttrDefaultN(), TCrossNet::IntType, TNEANet::IntType, TNEANet::IntVType, TCrossNet::IsDirected(), THash< TKey, TDat, THashFunc >::IsKey(), TVec< TVal, TSizeTy >::Len(), TNEANet::New(), TCrossNet::StrType, and TNEANet::StrType.

866  {
867  TIntPrIntH NodeMap;
868  THash<TIntPr, TIntPr> EdgeMap;
869  THashSet<TInt> Modes;
870  PNEANet NewNet = TNEANet::New();
871  //Add nodes and edges
872  for (int i = 0; i < CrossNetTypes.Len(); i++) {
873  TCrossNet& CrossNet = GetCrossNetById(CrossNetTypes[i]);
874  TInt Mode1 = CrossNet.GetMode1();
875  TInt Mode2 = CrossNet.GetMode2();
876  Modes.AddKey(Mode1);
877  Modes.AddKey(Mode2);
878  bool isDirected = CrossNet.IsDirected();
879  for(TCrossNet::TCrossEdgeI EdgeI = CrossNet.BegEdgeI(); EdgeI != CrossNet.EndEdgeI(); EdgeI++) {
880  int srcNode = EdgeI.GetSrcNId();
881  int dstNode = EdgeI.GetDstNId();
882  TIntPr SrcNodeMapping(Mode1, srcNode);
883  int srcId = 0;
884  if (NodeMap.IsKey(SrcNodeMapping)) {
885  srcId = NodeMap.GetDat(SrcNodeMapping);
886  } else {
887  srcId = NewNet->AddNode();
888  NodeMap.AddDat(SrcNodeMapping, srcId);
889  }
890  TIntPr DstNodeMapping(Mode2, dstNode);
891  int dstId = 0;
892  if (NodeMap.IsKey(DstNodeMapping)) {
893  dstId = NodeMap.GetDat(DstNodeMapping);
894  } else {
895  dstId = NewNet->AddNode();
896  NodeMap.AddDat(DstNodeMapping, dstId);
897  }
898  int edgeId = EdgeI.GetId();
899  TIntPr EdgeMapping(CrossNetTypes[i], edgeId);
900  int newEId = NewNet->AddEdge(srcId, dstId);
901  int otherEId = -1;
902  if (!isDirected) {
903  otherEId = NewNet->AddEdge(dstId, srcId);
904  }
905  EdgeMap.AddDat(EdgeMapping, TIntPr(newEId, otherEId));
906  }
907  }
908 
909  for (THashSet<TInt>::TIter it = Modes.BegI(); it != Modes.EndI(); it++) {
910  TModeNet &ModeNet = GetModeNetById(it.GetKey());
911  TInt ModeId = it.GetKey();
912  for(TModeNet::TNodeI NodeIt = ModeNet.BegMMNI(); NodeIt != ModeNet.EndMMNI(); NodeIt++) {
913  TIntPr NodeKey(ModeId, NodeIt.GetId());
914  if (!NodeMap.IsKey(NodeKey)) {
915  int newId = NewNet->AddNode();
916  NodeMap.AddDat(NodeKey, newId);
917  }
918  }
919  }
920 
921  //Add attributes
922  NewNet->AddIntAttrN(TStr("Mode"));
923  NewNet->AddIntAttrN(TStr("Id"));
924  NewNet->AddIntAttrE(TStr("CrossNet"));
925  NewNet->AddIntAttrE(TStr("Id"));
926  for(TIntPrIntH::TIter it = NodeMap.BegI(); it != NodeMap.EndI(); it++) {
927  NewNet->AddIntAttrDatN(it.GetDat(), it.GetKey().GetVal1(), TStr("Mode"));
928  NewNet->AddIntAttrDatN(it.GetDat(), it.GetKey().GetVal2(), TStr("Id"));
929  }
930  for(THash<TIntPr, TIntPr>::TIter it = EdgeMap.BegI(); it != EdgeMap.EndI(); it++) {
931  NewNet->AddIntAttrDatE(it.GetDat().GetVal1(), it.GetKey().GetVal1(), TStr("CrossNet"));
932  NewNet->AddIntAttrDatE(it.GetDat().GetVal1(), it.GetKey().GetVal2(), TStr("Id"));
933  if (it.GetDat().GetVal2() != -1) {
934  NewNet->AddIntAttrDatE(it.GetDat().GetVal2(), it.GetKey().GetVal1(), TStr("CrossNet"));
935  NewNet->AddIntAttrDatE(it.GetDat().GetVal2(), it.GetKey().GetVal2(), TStr("Id"));
936  }
937  }
938 
939  for (int i = 0; i < NodeAttrMap.Len(); i++) {
940  //mode, orig attr, new attr
941  TInt ModeId = NodeAttrMap[i].Val1;
942  TStr OrigAttr = NodeAttrMap[i].Val2;
943  TStr NewAttr = NodeAttrMap[i].Val3;
944  TModeNet& Net = GetModeNetById(ModeId);
945  int type = Net.GetAttrTypeN(OrigAttr);
946  if (type == TModeNet::IntType) {
947  NewNet->AddIntAttrN(NewAttr, Net.GetIntAttrDefaultN(OrigAttr));
948  for(TModeNet::TNodeI it = Net.BegMMNI(); it != Net.EndMMNI(); it++) {
949  TIntPr OldNId(ModeId, it.GetId());
950  int NewId = NodeMap.GetDat(OldNId);
951  int Val = Net.GetIntAttrDatN(it.GetId(), OrigAttr);
952  NewNet->AddIntAttrDatN(NewId, Val, NewAttr);
953  }
954  } else if (type == TModeNet::FltType) {
955  NewNet->AddFltAttrN(NewAttr, Net.GetFltAttrDefaultN(OrigAttr));
956  for(TModeNet::TNodeI it = Net.BegMMNI(); it != Net.EndMMNI(); it++) {
957  TIntPr OldNId(ModeId, it.GetId());
958  int NewId = NodeMap.GetDat(OldNId);
959  TFlt Val = Net.GetFltAttrDatN(it.GetId(), OrigAttr);
960  NewNet->AddFltAttrDatN(NewId, Val, NewAttr);
961  }
962 
963  } else if (type == TModeNet::StrType) {
964  NewNet->AddStrAttrN(NewAttr, Net.GetStrAttrDefaultN(OrigAttr));
965  for(TModeNet::TNodeI it = Net.BegMMNI(); it != Net.EndMMNI(); it++) {
966  TIntPr OldNId(ModeId, it.GetId());
967  int NewId = NodeMap.GetDat(OldNId);
968  TStr Val = Net.GetStrAttrDatN(it.GetId(), OrigAttr);
969  NewNet->AddStrAttrDatN(NewId, Val, NewAttr);
970  }
971  } else if (type == TModeNet::IntVType) {
972  NewNet->AddIntVAttrN(NewAttr);
973  for(TModeNet::TNodeI it = Net.BegMMNI(); it != Net.EndMMNI(); it++) {
974  TIntPr OldNId(ModeId, it.GetId());
975  int NewId = NodeMap.GetDat(OldNId);
976  TIntV Val = Net.GetIntVAttrDatN(it.GetId(), OrigAttr);
977  NewNet->AddIntVAttrDatN(NewId, Val, NewAttr);
978  }
979  }
980  }
981 
982  for (int i = 0; i < EdgeAttrMap.Len(); i++) {
983  //mode, orig attr, new attr
984  TInt CrossId = EdgeAttrMap[i].Val1;
985  TStr OrigAttr = EdgeAttrMap[i].Val2;
986  TStr NewAttr = EdgeAttrMap[i].Val3;
987  TCrossNet& Net = GetCrossNetById(CrossId);
988  int type = Net.GetAttrTypeE(OrigAttr);
989  if (type == TCrossNet::IntType) {
990  NewNet->AddIntAttrE(NewAttr, Net.GetIntAttrDefaultE(OrigAttr));
991  for(TCrossNet::TCrossEdgeI it = Net.BegEdgeI(); it != Net.EndEdgeI(); it++) {
992  TIntPr OldNId(CrossId, it.GetId());
993  TIntPr NewId = EdgeMap.GetDat(OldNId);
994  int Val = Net.GetIntAttrDatE(it.GetId(), OrigAttr);
995  NewNet->AddIntAttrDatE(NewId.Val1, Val, NewAttr);
996  if (NewId.Val2 != -1) {
997  NewNet->AddIntAttrDatE(NewId.Val2, Val, NewAttr);
998  }
999  }
1000  } else if (type == TCrossNet::FltType) {
1001  NewNet->AddFltAttrE(NewAttr, Net.GetFltAttrDefaultE(OrigAttr));
1002  for(TCrossNet::TCrossEdgeI it = Net.BegEdgeI(); it != Net.EndEdgeI(); it++) {
1003  TIntPr OldNId(CrossId, it.GetId());
1004  TIntPr NewId = EdgeMap.GetDat(OldNId);
1005  TFlt Val = Net.GetFltAttrDatE(it.GetId(), OrigAttr);
1006  NewNet->AddFltAttrDatE(NewId.Val1, Val, NewAttr);
1007  if (NewId.Val2 != -1) {
1008  NewNet->AddFltAttrDatE(NewId.Val2, Val, NewAttr);
1009  }
1010  }
1011 
1012  } else if (type == TCrossNet::StrType) {
1013  NewNet->AddStrAttrE(NewAttr, Net.GetStrAttrDefaultE(OrigAttr));
1014  for(TCrossNet::TCrossEdgeI it = Net.BegEdgeI(); it != Net.EndEdgeI(); it++){
1015  TIntPr OldNId(CrossId, it.GetId());
1016  TIntPr NewId = EdgeMap.GetDat(OldNId);
1017  TStr Val = Net.GetStrAttrDatE(it.GetId(), OrigAttr);
1018  NewNet->AddStrAttrDatE(NewId.Val1, Val, NewAttr);
1019  if (NewId.Val2 != -1) {
1020  NewNet->AddStrAttrDatE(NewId.Val2, Val, NewAttr);
1021  }
1022  }
1023  }
1024  }
1025  return NewNet;
1026 }
TStr GetStrAttrDatE(const TCrossEdgeI &EdgeI, const TStr &attr)
Gets the value of str attr from the edge attr value vector.
Definition: mmnet.h:417
TPair< TInt, TInt > TIntPr
Definition: ds.h:83
TInt GetIntAttrDatN(const TNodeI &NodeI, const TStr &attr)
Gets the value of int attr from the node attr value vector.
Definition: network.h:2701
TStr GetStrAttrDatN(const TNodeI &NodeI, const TStr &attr)
Gets the value of str attr from the node attr value vector.
Definition: network.h:2705
Node iterator. Only forward iteration (operator++) is supported.
Definition: mmnet.h:28
TIter BegI() const
Definition: shash.h:1105
TIter BegI() const
Definition: hash.h:213
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:575
TInt GetIntAttrDefaultE(const TStr &attribute) const
Gets Int edge attribute val. If not a proper attr, return default.
Definition: mmnet.h:314
TCrossEdgeI BegEdgeI() const
Definition: mmnet.h:335
Edge iterator. Only forward iteration (operator++) is supported.
Definition: mmnet.h:157
const TDat & GetDat(const TKey &Key) const
Definition: hash.h:262
TIntV GetIntVAttrDatN(const TNodeI &NodeI, const TStr &attr) const
Gets the value of the intv attr from the node attr value vector.
Definition: network.h:2711
TIter EndI() const
Definition: hash.h:218
TCrossEdgeI EndEdgeI() const
Definition: mmnet.h:336
TFlt GetFltAttrDefaultE(const TStr &attribute) const
Gets Flt edge attribute val. If not a proper attr, return default.
Definition: mmnet.h:318
Definition: dt.h:1383
TNodeI EndMMNI() const
Returns an iterator referring to the past-the-end node in the graph.
Definition: mmnet.h:84
int GetMode2() const
Gets the id of the dst mode.
Definition: mmnet.h:342
TFlt GetFltAttrDatN(const TNodeI &NodeI, const TStr &attr)
Gets the value of flt attr from the node attr value vector.
Definition: network.h:2708
TNodeI BegMMNI() const
Returns an iterator referring to the first node in the graph.
Definition: mmnet.h:82
int AddKey(const TKey &Key)
Definition: shash.h:1254
TStr GetStrAttrDefaultN(const TStr &attribute) const
Gets Str node attribute val. If not a proper attr, return default.
Definition: network.h:2015
The nodes of one particular mode in a TMMNet, and their neighbor vectors as TIntV attributes...
Definition: mmnet.h:23
Definition: dt.h:1134
TIter EndI() const
Definition: shash.h:1112
Definition: ds.h:32
TModeNet & GetModeNetById(const TInt &ModeId) const
Definition: mmnet.cpp:753
TFlt GetFltAttrDatE(const TCrossEdgeI &EdgeI, const TStr &attr)
Gets the value of flt attr from the edge attr value vector.
Definition: mmnet.h:420
Definition: dt.h:412
int GetMode1() const
Gets the id of the src mode.
Definition: mmnet.h:340
Definition: bd.h:196
TFlt GetFltAttrDefaultN(const TStr &attribute) const
Gets Flt node attribute val. If not a proper attr, return default.
Definition: network.h:2017
TInt GetIntAttrDefaultN(const TStr &attribute) const
Gets Int node attribute val. If not a proper attr, return default.
Definition: network.h:2013
bool IsKey(const TKey &Key) const
Definition: hash.h:258
static PNEANet New()
Static cons returns pointer to graph. Ex: PNEANet Graph=TNEANet::New().
Definition: network.h:2176
TDat & AddDat(const TKey &Key)
Definition: hash.h:238
TCrossNet & GetCrossNetById(const TInt &CrossId) const
Definition: mmnet.cpp:762
TInt GetIntAttrDatE(const TCrossEdgeI &EdgeI, const TStr &attr)
Gets the value of int attr from the edge attr value vector.
Definition: mmnet.h:414
bool IsDirected() const
Whether edges in the crossnet are directed.
Definition: mmnet.h:367
int GetAttrTypeN(const TStr &attr) const
Definition: mmnet.cpp:204
int GetAttrTypeE(const TStr &attr) const
Definition: mmnet.cpp:212
TStr GetStrAttrDefaultE(const TStr &attribute) const
Gets Str edge attribute val. If not a proper attr, return default.
Definition: mmnet.h:316
Implements a single CrossNet consisting of edges between two TModeNets (could be the same TModeNet) ...
Definition: mmnet.h:133

Here is the call graph for this function:

PNEANet TMMNet::ToNetwork2 ( TIntV CrossNetTypes,
TIntStrPrVH NodeAttrMap,
THash< TInt, TVec< TPair< TStr, TStr > > > &  EdgeAttrMap 
)

Converts multimodal network to TNEANet; as attr names can collide, AttrMap specifies the Mode/Cross Id -> vec of pairs (old att name, new attr name)

Definition at line 1028 of file mmnet.cpp.

References THash< TKey, TDat, THashFunc >::AddDat(), AddEdgeAttributes(), THashSet< TKey, THashFunc >::AddKey(), AddNodeAttributes(), TCrossNet::BegEdgeI(), THashSet< TKey, THashFunc >::BegI(), TModeNet::BegMMNI(), TCrossNet::EndEdgeI(), THashSet< TKey, THashFunc >::EndI(), TModeNet::EndMMNI(), GetCrossNetById(), THash< TKey, TDat, THashFunc >::GetDat(), TVec< TVal, TSizeTy >::GetDat(), TCrossNet::GetMode1(), TCrossNet::GetMode2(), GetModeNetById(), TCrossNet::IsDirected(), THash< TKey, TDat, THashFunc >::IsKey(), TVec< TVal, TSizeTy >::Len(), and TNEANet::New().

1028  {
1029  TIntPrIntH NodeMap;
1030  THashSet<TInt> Modes;
1031  PNEANet NewNet = TNEANet::New();
1032  NewNet->AddIntAttrN(TStr("Mode"));
1033  NewNet->AddIntAttrN(TStr("Id"));
1034  NewNet->AddIntAttrE(TStr("CrossNet"));
1035  NewNet->AddIntAttrE(TStr("Id"));
1036 
1037  //Add nodes and edges
1038  for (int i = 0; i < CrossNetTypes.Len(); i++) {
1039  TCrossNet& CrossNet = GetCrossNetById(CrossNetTypes[i]);
1040  TStrPrV CNetAttrs;
1041  if (EdgeAttrMap.IsKey(CrossNetTypes[i])) {
1042  CNetAttrs = EdgeAttrMap.GetDat(CrossNetTypes[i]);
1043  }
1044  TInt Mode1 = CrossNet.GetMode1();
1045  TInt Mode2 = CrossNet.GetMode2();
1046  TModeNet& Mode1Net = GetModeNetById(Mode1);
1047  TModeNet& Mode2Net = GetModeNetById(Mode2);
1048  TStrPrV Mode1Attrs;
1049  if (NodeAttrMap.IsKey(Mode1)) {
1050  Mode1Attrs = NodeAttrMap.GetDat(Mode1);
1051  }
1052  TStrPrV Mode2Attrs;
1053  if (NodeAttrMap.IsKey(Mode2)) {
1054  Mode2Attrs = NodeAttrMap.GetDat(Mode2);
1055  }
1056  Modes.AddKey(Mode1);
1057  Modes.AddKey(Mode2);
1058  bool isDirected = CrossNet.IsDirected();
1059  for(TCrossNet::TCrossEdgeI EdgeI = CrossNet.BegEdgeI(); EdgeI != CrossNet.EndEdgeI(); EdgeI++) {
1060  int srcNode = EdgeI.GetSrcNId();
1061  int dstNode = EdgeI.GetDstNId();
1062  TIntPr SrcNodeMapping(Mode1, srcNode);
1063  int srcId = 0;
1064  if (NodeMap.IsKey(SrcNodeMapping)) {
1065  srcId = NodeMap.GetDat(SrcNodeMapping);
1066  } else {
1067  srcId = NewNet->AddNode();
1068  NodeMap.AddDat(SrcNodeMapping, srcId);
1069  NewNet->AddIntAttrDatN(srcId, srcNode, TStr("Id"));
1070  NewNet->AddIntAttrDatN(srcId, Mode1, TStr("Mode"));
1071  AddNodeAttributes(NewNet, Mode1Net, Mode1Attrs, Mode1, srcNode, srcId);
1072  }
1073  TIntPr DstNodeMapping(Mode2, dstNode);
1074  int dstId = 0;
1075  if (NodeMap.IsKey(DstNodeMapping)) {
1076  dstId = NodeMap.GetDat(DstNodeMapping);
1077  } else {
1078  dstId = NewNet->AddNode();
1079  NodeMap.AddDat(DstNodeMapping, dstId);
1080  NewNet->AddIntAttrDatN(dstId, dstNode, TStr("Id"));
1081  NewNet->AddIntAttrDatN(dstId, Mode2, TStr("Mode"));
1082  AddNodeAttributes(NewNet, Mode2Net, Mode2Attrs, Mode2, dstNode, dstId);
1083  }
1084  int edgeId = EdgeI.GetId();
1085  int newEId = NewNet->AddEdge(srcId, dstId);
1086  NewNet->AddIntAttrDatE(newEId, edgeId, TStr("Id"));
1087  NewNet->AddIntAttrDatE(newEId, CrossNetTypes[i], TStr("CrossNet"));
1088  AddEdgeAttributes(NewNet, CrossNet, CNetAttrs, CrossNetTypes[i], edgeId, newEId);
1089  if (!isDirected) {
1090  int otherEId = NewNet->AddEdge(dstId, srcId);
1091  NewNet->AddIntAttrDatE(otherEId, edgeId, TStr("Id"));
1092  NewNet->AddIntAttrDatE(otherEId, CrossNetTypes[i], TStr("CrossNet"));
1093  AddEdgeAttributes(NewNet, CrossNet, CNetAttrs, CrossNetTypes[i], edgeId, otherEId);
1094  }
1095  }
1096  }
1097 
1098  for (THashSet<TInt>::TIter it = Modes.BegI(); it != Modes.EndI(); it++) {
1099  TInt ModeId = it.GetKey();
1100  TModeNet &ModeNet = GetModeNetById(ModeId);
1101  TStrPrV ModeAttrs = NodeAttrMap.GetDat(ModeId);
1102  for(TModeNet::TNodeI NodeIt = ModeNet.BegMMNI(); NodeIt != ModeNet.EndMMNI(); NodeIt++) {
1103  TIntPr NodeKey(ModeId, NodeIt.GetId());
1104  if (!NodeMap.IsKey(NodeKey)) {
1105  int newId = NewNet->AddNode();
1106  NodeMap.AddDat(NodeKey, newId);
1107  AddNodeAttributes(NewNet, ModeNet, ModeAttrs, ModeId, NodeIt.GetId(), newId);
1108  }
1109  }
1110  }
1111 
1112  return NewNet;
1113 }
Node iterator. Only forward iteration (operator++) is supported.
Definition: mmnet.h:28
TIter BegI() const
Definition: shash.h:1105
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:575
TCrossEdgeI BegEdgeI() const
Definition: mmnet.h:335
Edge iterator. Only forward iteration (operator++) is supported.
Definition: mmnet.h:157
const TDat & GetDat(const TKey &Key) const
Definition: hash.h:262
TCrossEdgeI EndEdgeI() const
Definition: mmnet.h:336
TNodeI EndMMNI() const
Returns an iterator referring to the past-the-end node in the graph.
Definition: mmnet.h:84
int GetMode2() const
Gets the id of the dst mode.
Definition: mmnet.h:342
TNodeI BegMMNI() const
Returns an iterator referring to the first node in the graph.
Definition: mmnet.h:82
int AddKey(const TKey &Key)
Definition: shash.h:1254
int AddNodeAttributes(PNEANet &NewNet, TModeNet &Net, TVec< TPair< TStr, TStr > > &Attrs, int ModeId, int oldId, int NId)
Definition: mmnet.cpp:1314
The nodes of one particular mode in a TMMNet, and their neighbor vectors as TIntV attributes...
Definition: mmnet.h:23
Definition: dt.h:1134
TIter EndI() const
Definition: shash.h:1112
Definition: ds.h:32
TModeNet & GetModeNetById(const TInt &ModeId) const
Definition: mmnet.cpp:753
Definition: dt.h:412
int GetMode1() const
Gets the id of the src mode.
Definition: mmnet.h:340
Definition: bd.h:196
bool IsKey(const TKey &Key) const
Definition: hash.h:258
int AddEdgeAttributes(PNEANet &NewNet, TCrossNet &Net, TVec< TPair< TStr, TStr > > &Attrs, int CrossId, int oldId, int EId)
Definition: mmnet.cpp:1341
static PNEANet New()
Static cons returns pointer to graph. Ex: PNEANet Graph=TNEANet::New().
Definition: network.h:2176
TDat & AddDat(const TKey &Key)
Definition: hash.h:238
TCrossNet & GetCrossNetById(const TInt &CrossId) const
Definition: mmnet.cpp:762
bool IsDirected() const
Whether edges in the crossnet are directed.
Definition: mmnet.h:367
Vector is a sequence TVal objects representing an array that can change in size.
Definition: ds.h:430
Implements a single CrossNet consisting of edges between two TModeNets (could be the same TModeNet) ...
Definition: mmnet.h:133

Here is the call graph for this function:

PNEANetMP TMMNet::ToNetworkMP ( TStrV CrossNetNames)

Definition at line 1136 of file mmnet.cpp.

References TVec< TVal, TSizeTy >::Add(), THashMP< TKey, TDat, THashFunc >::AddDat(), THash< TKey, TDat, THashFunc >::AddDat(), THashSet< TKey, THashFunc >::AddKey(), TVec< TVal, TSizeTy >::AddV(), THashSet< TKey, THashFunc >::BegI(), edge, THashSet< TKey, THashFunc >::EndI(), GetCrossId(), GetCrossNetByName(), THashMP< TKey, TDat, THashFunc >::GetDat(), THash< TKey, TDat, THashFunc >::GetDat(), TCrossNet::TCrossEdgeI::GetDstNId(), TCrossNet::GetEdge(), TCrossNet::GetEdgeI(), TCrossNet::GetEdges(), THashMP< TKey, TDat, THashFunc >::GetKeyV(), THash< TKey, TDat, THashFunc >::GetKeyV(), TCrossNet::GetMode1(), TCrossNet::GetMode2(), GetModeNetById(), TCrossNet::GetMxEId(), TModeNet::GetNeighborsByCrossNet(), TNEANet::GetNodes(), GetPartitionRanges(), TCrossNet::TCrossEdge::GetSrcNId(), TCrossNet::TCrossEdgeI::GetSrcNId(), TPair< TVal1, TVal2 >::GetVal1(), TPair< TVal1, TVal2 >::GetVal2(), TCrossNet::IsDirected(), TCrossNet::IsEdge(), THash< TKey, TDat, THashFunc >::IsKey(), TNEANet::IsNode(), TVec< TVal, TSizeTy >::Len(), TCrossNet::MxEId, TModeNet::NeighborTypes, TNEANetMP::New(), and TNEANet::NodeH.

1136  {
1137 
1138  TStrIntH CrossNetStart;
1139  THashSet<TInt> ModeSet;
1140  int offset = 0;
1141  int NumEdges = 0;
1142  TVec<TCrossNet> CrossNets;
1143  for (int i=0; i < CrossNetNames.Len(); i++) {
1144  CrossNets.Add(GetCrossNetByName(CrossNetNames[i]));
1145  CrossNetStart.AddDat(CrossNetNames[i], offset);
1146  TCrossNet& CrossNet = GetCrossNetByName(CrossNetNames[i]);
1147  int factor = CrossNet.IsDirected() ? 1 : 2;
1148  offset += (CrossNet.GetMxEId() * factor);
1149  NumEdges += (CrossNet.GetEdges() * factor);
1150  ModeSet.AddKey(CrossNet.GetMode1());
1151  ModeSet.AddKey(CrossNet.GetMode2());
1152  }
1153  int MxEId = offset;
1154  int NumNodes = 0;
1155  for (THashSet<TInt>::TIter MI = ModeSet.BegI(); MI < ModeSet.EndI(); MI++) {
1156  TModeNet& ModeNet = GetModeNetById(MI.GetKey());
1157  NumNodes += ModeNet.GetNodes();
1158  }
1159  THashMP<TIntPr, TInt> NodeMap(NumNodes);
1160  THashMP<TIntPr, TIntPr> EdgeMap(NumEdges);
1161  PNEANetMP NewNet = TNEANetMP::New(NumNodes, NumEdges);
1162 
1163  int num_threads = omp_get_max_threads();
1164  offset = 0;
1165  for (THashSet<TInt>::TIter MI = ModeSet.BegI(); MI < ModeSet.EndI(); MI++) {
1166  TInt ModeId = MI.GetKey();
1167  TModeNet& ModeNet = GetModeNetById(ModeId);
1168  TIntV KeyIds;
1169  ModeNet.NodeH.GetKeyV(KeyIds);
1170 
1171  TIntPrV NodePartitions;
1172  GetPartitionRanges(NodePartitions, num_threads, KeyIds.Len());
1173  int curr_nid;
1174  #pragma omp parallel for schedule(static) private(curr_nid)
1175  for (int i = 0; i < NodePartitions.Len(); i++) {
1176  TInt CurrStart = NodePartitions[i].GetVal1();
1177  TInt CurrEnd = NodePartitions[i].GetVal2();
1178  curr_nid = offset + CurrStart;
1179  for (int idx = CurrStart; idx < CurrEnd ; idx++) {
1180  int n_i = KeyIds[idx];
1181  if (ModeNet.IsNode(n_i)) {
1182  //Collect neighbors
1183  TIntV InNbrs;
1184  TIntV OutNbrs;
1185  for (int j=0; j < CrossNetNames.Len(); j++) {
1186  TStr CrossNetName = TStr(CrossNetNames[j].CStr());
1187  if (ModeNet.NeighborTypes.IsKey(CrossNetName)) {
1188  if (ModeNet.NeighborTypes.GetDat(CrossNetName)) {
1189 
1190  TIntV Neighbors;
1191  ModeNet.GetNeighborsByCrossNet(n_i, CrossNetName, Neighbors);
1192  int edge_offset = CrossNetStart.GetDat(CrossNetName);
1193  TCrossNet& CrossNet = GetCrossNetByName(CrossNetName);
1194  //TCrossNet* CrossNet = &CrossNets[j];
1195  bool isDir = CrossNet.IsDirected();
1196  bool isOutNbr = CrossNet.GetMode1() == ModeId;
1197  int factor = isDir ? 1 : 2;
1198 
1199  int id_offset = isDir || isOutNbr ? 0 : 1;
1200  if (!isDir && CrossNet.GetMode1() == CrossNet.GetMode2()) {
1201  id_offset = n_i == CrossNet.GetEdge(n_i).GetSrcNId() ? 0 : 1;
1202  }
1203 
1204  for (int k = 0; k < Neighbors.Len(); k++) {
1205  if (isOutNbr && id_offset == 0) {
1206  OutNbrs.Add(edge_offset + Neighbors[k]*factor + id_offset);
1207  } else {
1208  InNbrs.Add(edge_offset + Neighbors[k]*factor + id_offset);
1209  }
1210  if (!isDir) {
1211  int opp_offset = id_offset == 1 ? 0 : 1;
1212  if (isOutNbr && id_offset == 0) {
1213  InNbrs.Add(edge_offset + Neighbors[k]*factor + opp_offset);
1214  } else {
1215  OutNbrs.Add(edge_offset + Neighbors[k]*factor + opp_offset);
1216  }
1217  }
1218  }
1219  } else {
1220  TIntV TempOut;
1221  ModeNet.GetNeighborsByCrossNet(n_i, CrossNetName, TempOut, true);
1222  OutNbrs.AddV(TempOut);
1223  TIntV TempIn;
1224  ModeNet.GetNeighborsByCrossNet(n_i, CrossNetName, TempIn, false);
1225  InNbrs.AddV(TempIn);
1226  }
1227  }
1228  }
1229 
1230  NewNet->AddNodeWithEdges(curr_nid, InNbrs, OutNbrs);
1231  TIntPr NodeKey(MI.GetKey(), n_i);
1232  NodeMap.AddDat(NodeKey, curr_nid);
1233  curr_nid++;
1234  }
1235  }
1236  }
1237  offset += KeyIds.Len();
1238  }
1239  NewNet->SetNodes(offset);
1240 
1241  for (int j=0; j < CrossNetNames.Len(); j++) {
1242  TStr CrossNetName = CrossNetNames[j];
1243  TCrossNet& CrossNet = GetCrossNetByName(CrossNetName);
1244  TInt CrossNetId = GetCrossId(CrossNetName);
1245  TInt Mode1 = CrossNet.GetMode1();
1246  TInt Mode2 = CrossNet.GetMode2();
1247  TIntPrV EdgePartitions;
1248  GetPartitionRanges(EdgePartitions, num_threads, CrossNet.MxEId);
1249  int curr_eid;
1250  offset = CrossNetStart.GetDat(CrossNetNames[j]);
1251  int factor = CrossNet.IsDirected() ? 1 : 2;
1252  #pragma omp parallel for schedule(static) private(curr_eid)
1253  for (int i = 0; i < EdgePartitions.Len(); i++) {
1254  TInt CurrStart = EdgePartitions[i].GetVal1();
1255  TInt CurrEnd = EdgePartitions[i].GetVal2();
1256  for (int e_i = CurrStart; e_i < CurrEnd ; e_i++) {
1257  curr_eid = offset + factor*e_i;
1258  if (CrossNet.IsEdge(e_i)) {
1259  int new_eid = curr_eid;
1260  TIntPr EdgeKey(CrossNetId, e_i);
1261  TCrossNet::TCrossEdgeI edge = CrossNet.GetEdgeI(e_i);
1262  int srcNode = edge.GetSrcNId();
1263  int dstNode = edge.GetDstNId();
1264  TIntPr NodeKeySrc(Mode1, srcNode);
1265  TIntPr NodeKeyDst(Mode2, dstNode);
1266  int newSrc = NodeMap.GetDat(NodeKeySrc);
1267  int newDst = NodeMap.GetDat(NodeKeyDst);
1268  NewNet->AddEdgeUnchecked(curr_eid, newSrc, newDst);
1269  curr_eid++;
1270  int otherEId = -1;
1271  if (!CrossNet.IsDirected()) {
1272  otherEId = curr_eid;
1273  NewNet->AddEdgeUnchecked(otherEId, newDst, newSrc);
1274  }
1275  EdgeMap.AddDat(EdgeKey, TIntPr(new_eid, otherEId));
1276  }
1277  }
1278  }
1279  }
1280  NewNet->SetEdges(MxEId);
1281  NewNet->ReserveAttr(2, 0, 0, 2, 0, 0);
1282 
1283  //Add attributes
1284  NewNet->AddIntAttrN(TStr("Mode"));
1285  NewNet->AddIntAttrN(TStr("Id"));
1286  NewNet->AddIntAttrE(TStr("CrossNet"));
1287  NewNet->AddIntAttrE(TStr("Id"));
1288 
1289  TIntPrV NewNodeIds;
1290  NodeMap.GetKeyV(NewNodeIds);
1291 
1292  #pragma omp parallel for schedule(static)
1293  for(int i = 0; i < NewNodeIds.Len(); i++) {
1294  NewNet->AddIntAttrDatN(NodeMap.GetDat(NewNodeIds[i]), NewNodeIds[i].GetVal1(), TStr("Mode"));
1295  NewNet->AddIntAttrDatN(NodeMap.GetDat(NewNodeIds[i]), NewNodeIds[i].GetVal2(), TStr("Id"));
1296  }
1297 
1298  TIntPrV NewEdgeIds;
1299  EdgeMap.GetKeyV(NewEdgeIds);
1300  #pragma omp parallel for schedule(static)
1301  for(int i = 0; i < NewEdgeIds.Len(); i++) {
1302  NewNet->AddIntAttrDatE(EdgeMap.GetDat(NewEdgeIds[i]).GetVal1(), NewEdgeIds[i].GetVal2(), TStr("Id"));
1303  NewNet->AddIntAttrDatE(EdgeMap.GetDat(NewEdgeIds[i]).GetVal1(), NewEdgeIds[i].GetVal1(), TStr("CrossNet"));
1304  if (EdgeMap.GetDat(NewEdgeIds[i]).GetVal2() != -1) {
1305  NewNet->AddIntAttrDatE(EdgeMap.GetDat(NewEdgeIds[i]).GetVal2(), NewEdgeIds[i].GetVal1(), TStr("CrossNet"));
1306  NewNet->AddIntAttrDatE(EdgeMap.GetDat(NewEdgeIds[i]).GetVal2(), NewEdgeIds[i].GetVal2(), TStr("Id"));
1307  }
1308  }
1309  return NewNet;
1310 }
TPair< TInt, TInt > TIntPr
Definition: ds.h:83
int GetNodes() const
Returns the number of nodes in the network.
Definition: network.h:2276
void GetPartitionRanges(TIntPrV &Partitions, const TInt &NumPartitions, const TInt &MxVal) const
Definition: mmnet.cpp:1115
TIter BegI() const
Definition: shash.h:1105
static PNEANetMP New()
Static cons returns pointer to graph. Ex: PNEANetMP Graph=TNEANetMP::New().
Definition: networkmp.h:316
int GetSrcNId() const
Returns the source of the edge.
Definition: mmnet.h:174
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:575
Edge iterator. Only forward iteration (operator++) is supported.
Definition: mmnet.h:157
const TDat & GetDat(const TKey &Key) const
Definition: hash.h:262
TCrossEdge & GetEdge(int eid)
Definition: mmnet.h:320
void GetNeighborsByCrossNet(const int &NId, TStr &Name, TIntV &Neighbors, const bool isOutEId=false) const
For the given node, gets all the neighbors for the crossnet type. If this mode is both the source and...
Definition: mmnet.cpp:113
int GetMode2() const
Gets the id of the dst mode.
Definition: mmnet.h:342
int GetSrcNId() const
Definition: mmnet.h:151
int AddKey(const TKey &Key)
Definition: shash.h:1254
int GetDstNId() const
Returns the destination of the edge.
Definition: mmnet.h:176
The nodes of one particular mode in a TMMNet, and their neighbor vectors as TIntV attributes...
Definition: mmnet.h:23
Definition: dt.h:1134
THash< TStr, TBool > NeighborTypes
Definition: mmnet.h:48
TIter EndI() const
Definition: shash.h:1112
Definition: ds.h:32
int GetEdges() const
Returns the number of edges in the graph.
Definition: mmnet.h:327
TModeNet & GetModeNetById(const TInt &ModeId) const
Definition: mmnet.cpp:753
int GetMxEId() const
Definition: mmnet.h:325
void GetKeyV(TVec< TKey > &KeyV) const
Definition: hash.h:484
Definition: dt.h:412
TCrossEdgeI GetEdgeI(const int &EId) const
Edge iterators.
Definition: mmnet.h:334
int GetCrossId(const TStr &CrossName) const
Gets the crossnet id from the crossnet name.
Definition: mmnet.h:638
int GetMode1() const
Gets the id of the src mode.
Definition: mmnet.h:340
Hash-Table with multiprocessing support.
Definition: hashmp.h:81
Definition: bd.h:196
bool IsNode(const int &NId) const
Tests whether ID NId is a node.
Definition: network.h:2298
THash< TInt, TNode > NodeH
Definition: network.h:2028
bool IsEdge(const int &EId) const
Tests whether an edge with edge ID EId exists in the graph.
Definition: mmnet.h:323
TInt MxEId
The HashTable from Edge id to the corresponding Edge.
Definition: mmnet.h:265
bool IsKey(const TKey &Key) const
Definition: hash.h:258
TCrossNet & GetCrossNetByName(const TStr &CrossName) const
Gets a reference to the crossnet.
Definition: mmnet.cpp:758
TSizeTy Add()
Adds a new element at the end of the vector, after its current last element.
Definition: ds.h:602
TDat & AddDat(const TKey &Key)
Definition: hash.h:238
bool IsDirected() const
Whether edges in the crossnet are directed.
Definition: mmnet.h:367
Vector is a sequence TVal objects representing an array that can change in size.
Definition: ds.h:430
TSizeTy AddV(const TVec< TVal, TSizeTy > &ValV)
Adds the elements of the vector ValV to the to end of the vector.
Definition: ds.h:1110
Implements a single CrossNet consisting of edges between two TModeNets (could be the same TModeNet) ...
Definition: mmnet.h:133

Here is the call graph for this function:

Friends And Related Function Documentation

friend class TCrossNet
friend

Definition at line 572 of file mmnet.h.

Referenced by AddCrossNet().

friend class TModeNet
friend

Definition at line 573 of file mmnet.h.

Member Data Documentation

TCRef TMMNet::CRef

Definition at line 556 of file mmnet.h.

THash<TInt,TStr> TMMNet::CrossIdToNameH
private
THash<TStr,TInt> TMMNet::CrossNameToIdH
private
THash<TInt,TStr> TMMNet::ModeIdToNameH
private
THash<TStr,TInt> TMMNet::ModeNameToIdH
private
TInt TMMNet::MxCrossNetId
private

Keeps track of the max mode id.

Definition at line 561 of file mmnet.h.

Referenced by AddCrossNet(), LoadNetworkShM(), and Save().

TInt TMMNet::MxModeId
private

Definition at line 560 of file mmnet.h.

Referenced by AddModeNet(), LoadNetworkShM(), and Save().


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