SNAP Library 3.0, Developer Reference  2016-07-20 17:56:49
SNAP, a general purpose, high performance system for analysis and manipulation of large networks
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
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  TModeNetI
 TModeNet iterator. Only forward iteration (operator++) is supported. More...
 

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...
 
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 New ()
 

Public Attributes

TCRef CRef
 

Private Member Functions

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 468 of file mmnet.h.

Constructor & Destructor Documentation

TMMNet::TMMNet ( )
inline

Definition at line 540 of file mmnet.h.

Referenced by Load(), and New().

TInt MxModeId
Definition: mmnet.h:524
THash< TInt, TStr > ModeIdToNameH
Definition: mmnet.h:529
THash< TInt, TCrossNet > TCrossNetH
Definition: mmnet.h:527
TCRef CRef
Definition: mmnet.h:520
THash< TStr, TInt > ModeNameToIdH
Definition: mmnet.h:530
THash< TStr, TInt > CrossNameToIdH
Definition: mmnet.h:533
THash< TInt, TModeNet > TModeNetH
Keeps track of the max crossnet id.
Definition: mmnet.h:526
TInt MxCrossNetId
Keeps track of the max mode id.
Definition: mmnet.h:525
THash< TInt, TStr > CrossIdToNameH
Definition: mmnet.h:532

Here is the caller graph for this function:

TMMNet::TMMNet ( const TMMNet OtherTMMNet)
inline

Definition at line 541 of file mmnet.h.

541  : MxModeId(OtherTMMNet.MxModeId), MxCrossNetId(OtherTMMNet.MxCrossNetId), TModeNetH(OtherTMMNet.TModeNetH),
542  TCrossNetH(OtherTMMNet.TCrossNetH), ModeIdToNameH(OtherTMMNet.ModeIdToNameH), ModeNameToIdH(OtherTMMNet.ModeNameToIdH), CrossIdToNameH(OtherTMMNet.CrossIdToNameH), CrossNameToIdH(OtherTMMNet.CrossNameToIdH) {}
TInt MxModeId
Definition: mmnet.h:524
THash< TInt, TStr > ModeIdToNameH
Definition: mmnet.h:529
THash< TInt, TCrossNet > TCrossNetH
Definition: mmnet.h:527
THash< TStr, TInt > ModeNameToIdH
Definition: mmnet.h:530
THash< TStr, TInt > CrossNameToIdH
Definition: mmnet.h:533
THash< TInt, TModeNet > TModeNetH
Keeps track of the max crossnet id.
Definition: mmnet.h:526
TInt MxCrossNetId
Keeps track of the max mode id.
Definition: mmnet.h:525
THash< TInt, TStr > CrossIdToNameH
Definition: mmnet.h:532
TMMNet::TMMNet ( TSIn SIn)
inline

Definition at line 543 of file mmnet.h.

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

543  : MxModeId(SIn), MxCrossNetId(SIn), TModeNetH(SIn), TCrossNetH(SIn), ModeIdToNameH(SIn), ModeNameToIdH(SIn), CrossIdToNameH(SIn), CrossNameToIdH(SIn) {
544  for (THash<TInt, TModeNet>::TIter it = TModeNetH.BegI(); it < TModeNetH.EndI(); it++) {
545  it.GetDat().SetParentPointer(this);
546  }
547  for (THash<TInt, TCrossNet>::TIter it = TCrossNetH.BegI(); it < TCrossNetH.EndI(); it++) {
548  it.GetDat().SetParentPointer(this);
549  }
550  }
TInt MxModeId
Definition: mmnet.h:524
TIter BegI() const
Definition: hash.h:171
const TDat & GetDat(const TKey &Key) const
Definition: hash.h:220
TIter EndI() const
Definition: hash.h:176
THash< TInt, TStr > ModeIdToNameH
Definition: mmnet.h:529
THash< TInt, TCrossNet > TCrossNetH
Definition: mmnet.h:527
THash< TStr, TInt > ModeNameToIdH
Definition: mmnet.h:530
THash< TStr, TInt > CrossNameToIdH
Definition: mmnet.h:533
THash< TInt, TModeNet > TModeNetH
Keeps track of the max crossnet id.
Definition: mmnet.h:526
Definition: hash.h:88
TInt MxCrossNetId
Keeps track of the max mode id.
Definition: mmnet.h:525
THash< TInt, TStr > CrossIdToNameH
Definition: mmnet.h:532

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 620 of file mmnet.cpp.

References GetModeId().

620  {
621  TInt ModeId1 = GetModeId(ModeName1);
622  TInt ModeId2 = GetModeId(ModeName2);
623  return AddCrossNet(ModeId1, ModeId2, CrossNetName, isDir);
624 }
int GetModeId(const TStr &ModeName) const
Gets the mode id from the mode name.
Definition: mmnet.h:572
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:620
Definition: dt.h:1044

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 626 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.

626  {
627  if (CrossNameToIdH.IsKey(CrossNetName)) {
628  return -1;
629  }
630  TInt CrossNetId = TInt(MxCrossNetId);
631  MxCrossNetId++;
632  CrossIdToNameH.AddDat(CrossNetId, CrossNetName);
633  CrossNameToIdH.AddDat(CrossNetName, CrossNetId);
634 
635  TCrossNet Cross = TCrossNet(ModeId1, ModeId2, isDir, CrossNetId);
636  Cross.SetParentPointer(this);
637  TCrossNetH.AddDat(CrossNetId, Cross);
638 
639  TModeNetH.GetDat(ModeId1).AddNbrType(CrossNetName, ModeId1==ModeId2, isDir);
640  TModeNetH.GetDat(ModeId2).AddNbrType(CrossNetName, ModeId1==ModeId2, isDir);
641 
642  return CrossNetId;
643 }
const TDat & GetDat(const TKey &Key) const
Definition: hash.h:220
THash< TInt, TCrossNet > TCrossNetH
Definition: mmnet.h:527
THash< TStr, TInt > CrossNameToIdH
Definition: mmnet.h:533
int AddNbrType(const TStr &CrossName, const bool sameMode, bool isDir)
Definition: mmnet.cpp:82
Definition: dt.h:1044
THash< TInt, TModeNet > TModeNetH
Keeps track of the max crossnet id.
Definition: mmnet.h:526
void SetParentPointer(TMMNet *parent)
Definition: mmnet.cpp:280
friend class TCrossNet
Definition: mmnet.h:536
bool IsKey(const TKey &Key) const
Definition: hash.h:216
TInt MxCrossNetId
Keeps track of the max mode id.
Definition: mmnet.h:525
TDat & AddDat(const TKey &Key)
Definition: hash.h:196
THash< TInt, TStr > CrossIdToNameH
Definition: mmnet.h:532
Implements a single CrossNet consisting of edges between two TModeNets (could be the same TModeNet) ...
Definition: mmnet.h:124

Here is the call graph for this function:

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

Definition at line 714 of file mmnet.cpp.

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

714  {
715  CrossIdToNameH.AddDat(CrossNetId, CrossNetName);
716  CrossNameToIdH.AddDat(CrossNetName, CrossNetId);
717 
718  TCrossNetH.AddDat(CrossNetId, CrossNet);
719  TCrossNetH[CrossNetId].SetParentPointer(this);
720  return CrossNetId;
721 }
THash< TInt, TCrossNet > TCrossNetH
Definition: mmnet.h:527
THash< TStr, TInt > CrossNameToIdH
Definition: mmnet.h:533
TDat & AddDat(const TKey &Key)
Definition: hash.h:196
THash< TInt, TStr > CrossIdToNameH
Definition: mmnet.h:532

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 1276 of file mmnet.cpp.

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

Referenced by ToNetwork2().

1276  {
1277  for (int i = 0; i < Attrs.Len(); i++) {
1278  //mode, orig attr, new attr
1279  TStr OrigAttr = Attrs[i].Val1;
1280  TStr NewAttr = Attrs[i].Val2;
1281  int type = Net.GetAttrTypeE(OrigAttr);
1282  if (type == TCrossNet::IntType) {
1283  TIntPr OldNId(CrossId, oldId);
1284  TInt Val = Net.GetIntAttrDatE(oldId, OrigAttr);
1285  NewNet->AddIntAttrDatE(EId, Val, NewAttr);
1286  } else if (type == TCrossNet::FltType) {
1287  TIntPr OldNId(CrossId, oldId);
1288  TFlt Val = Net.GetFltAttrDatE(oldId, OrigAttr);
1289  NewNet->AddFltAttrDatE(EId, Val, NewAttr);
1290  } else if (type == TCrossNet::StrType) {
1291  TIntPr OldNId(CrossId, oldId);
1292  TStr Val = Net.GetStrAttrDatE(oldId, OrigAttr);
1293  NewNet->AddStrAttrDatE(EId, Val, NewAttr);
1294  }
1295  }
1296  return 0;
1297 }
TStr GetStrAttrDatE(const TCrossEdgeI &EdgeI, const TStr &attr)
Gets the value of str attr from the edge attr value vector.
Definition: mmnet.h:381
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:547
Definition: dt.h:1293
Definition: dt.h:1044
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:384
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:378
int GetAttrTypeE(const TStr &attr) const
Definition: mmnet.cpp:167

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 705 of file mmnet.cpp.

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

705  {
706  ModeIdToNameH.AddDat(ModeId, ModeName);
707  ModeNameToIdH.AddDat(ModeName, ModeId);
708 
709  TModeNetH.AddDat(ModeId, ModeNet);
710  TModeNetH[ModeId].SetParentPointer(this);
711  return ModeId;
712 
713 }
THash< TInt, TStr > ModeIdToNameH
Definition: mmnet.h:529
THash< TStr, TInt > ModeNameToIdH
Definition: mmnet.h:530
THash< TInt, TModeNet > TModeNetH
Keeps track of the max crossnet id.
Definition: mmnet.h:526
TDat & AddDat(const TKey &Key)
Definition: hash.h:196

Here is the call graph for this function:

int TMMNet::AddModeNet ( const TStr ModeName)

Adds a mode to the multimodal network.

Definition at line 605 of file mmnet.cpp.

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

605  {
606  if (ModeNameToIdH.IsKey(ModeName)) {
607  return -1;
608  }
609  TInt ModeId = TInt(MxModeId);
610  MxModeId++;
611  ModeIdToNameH.AddDat(ModeId, ModeName);
612  ModeNameToIdH.AddDat(ModeName, ModeId);
613 
614  TModeNet NewGraph(ModeId);
615  NewGraph.SetParentPointer(this);
616  TModeNetH.AddDat(ModeId, NewGraph);
617  return ModeId;
618 }
TInt MxModeId
Definition: mmnet.h:524
THash< TInt, TStr > ModeIdToNameH
Definition: mmnet.h:529
THash< TStr, TInt > ModeNameToIdH
Definition: mmnet.h:530
The nodes of one particular mode in a TMMNet, and their neighbor vectors as TIntV attributes...
Definition: mmnet.h:23
Definition: dt.h:1044
THash< TInt, TModeNet > TModeNetH
Keeps track of the max crossnet id.
Definition: mmnet.h:526
bool IsKey(const TKey &Key) const
Definition: hash.h:216
TDat & AddDat(const TKey &Key)
Definition: hash.h:196

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 1249 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().

1249  {
1250  for (int i = 0; i < Attrs.Len(); i++) {
1251  //mode, orig attr, new attr
1252  TStr OrigAttr = Attrs[i].Val1;
1253  TStr NewAttr = Attrs[i].Val2;
1254  int type = Net.GetAttrTypeN(OrigAttr);
1255  if (type == TModeNet::IntType) {
1256  TIntPr OldNId(ModeId, oldId);
1257  TInt Val = Net.GetIntAttrDatN(oldId, OrigAttr);
1258  NewNet->AddIntAttrDatN(NId, Val, NewAttr);
1259  } else if (type == TModeNet::FltType) {
1260  TIntPr OldNId(ModeId, oldId);
1261  TFlt Val = Net.GetFltAttrDatN(oldId, OrigAttr);
1262  NewNet->AddFltAttrDatN(NId, Val, NewAttr);
1263  } else if (type == TModeNet::StrType) {
1264  TIntPr OldNId(ModeId, oldId);
1265  TStr Val = Net.GetStrAttrDatN(oldId, OrigAttr);
1266  NewNet->AddStrAttrDatN(NId, Val, NewAttr);
1267  } else if (type == TModeNet::IntVType) {
1268  TIntPr OldNId(ModeId, oldId);
1269  TIntV Val = Net.GetIntVAttrDatN(oldId, OrigAttr);
1270  NewNet->AddIntVAttrDatN(NId, Val, NewAttr);
1271  }
1272  }
1273  return 0;
1274 }
TInt GetIntAttrDatN(const TNodeI &NodeI, const TStr &attr)
Gets the value of int attr from the node attr value vector.
Definition: network.h:2304
TStr GetStrAttrDatN(const TNodeI &NodeI, const TStr &attr)
Gets the value of str attr from the node attr value vector.
Definition: network.h:2308
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:547
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:2314
Definition: dt.h:1293
TFlt GetFltAttrDatN(const TNodeI &NodeI, const TStr &attr)
Gets the value of flt attr from the node attr value vector.
Definition: network.h:2311
Definition: dt.h:1044
Definition: ds.h:32
Definition: dt.h:412
int GetAttrTypeN(const TStr &attr) const
Definition: mmnet.cpp:159

Here is the call graph for this function:

Here is the caller graph for this function:

TCrossNetI TMMNet::BegCrossNetI ( ) const
inline

Definition at line 590 of file mmnet.h.

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

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

Here is the call graph for this function:

TModeNetI TMMNet::BegModeNetI ( ) const
inline

Definition at line 595 of file mmnet.h.

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

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

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 723 of file mmnet.cpp.

References CrossIdToNameH, and TModeNetH.

Referenced by TCrossNet::Clr().

723  {
724  TStr CrossNetName = CrossIdToNameH[CrossNetId];
725  TModeNetH[ModeId].ClrNbr(CrossNetName, outEdge, sameMode, isDir);
726 }
THash< TInt, TModeNet > TModeNetH
Keeps track of the max crossnet id.
Definition: mmnet.h:526
Definition: dt.h:412
THash< TInt, TStr > CrossIdToNameH
Definition: mmnet.h:532

Here is the caller graph for this function:

int TMMNet::DelCrossNet ( const TInt CrossNetId)

Deletes a crossnet from the multimodal network.

Definition at line 645 of file mmnet.cpp.

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

Referenced by DelModeNet().

645  {
646  return DelCrossNet(CrossIdToNameH.GetDat(CrossNetId));
647 }
int DelCrossNet(const TInt &CrossNetId)
Deletes a crossnet from the multimodal network.
Definition: mmnet.cpp:645
const TDat & GetDat(const TKey &Key) const
Definition: hash.h:220
THash< TInt, TStr > CrossIdToNameH
Definition: mmnet.h:532

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 649 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.

649  {
650  IAssertR(CrossNameToIdH.IsKey(CrossNet),TStr::Fmt("No such link type: %s", CrossNet.CStr()));
651  TInt CrossNetId = CrossNameToIdH.GetDat(CrossNet);
652  TInt Mode1 = GetCrossNetById(CrossNetId).Mode1;
653  TInt Mode2 = GetCrossNetById(CrossNetId).Mode2;
654  if (GetModeNetById(Mode1).DelNbrType(CrossNet) == -1 || (Mode1 != Mode2 && GetModeNetById(Mode2).DelNbrType(CrossNet) == -1)) {
655  return -1;
656  }
657  CrossNameToIdH.DelKey(CrossNet);
658  CrossIdToNameH.DelKey(CrossNetId);
659  GetCrossNetById(CrossNetId).SetParentPointer(NULL);
660  TCrossNetH.DelKey(CrossNetId);
661  return 0;
662 }
#define IAssertR(Cond, Reason)
Definition: bd.h:265
const TDat & GetDat(const TKey &Key) const
Definition: hash.h:220
THash< TInt, TCrossNet > TCrossNetH
Definition: mmnet.h:527
void DelKey(const TKey &Key)
Definition: hash.h:362
THash< TStr, TInt > CrossNameToIdH
Definition: mmnet.h:533
Definition: dt.h:1044
void SetParentPointer(TMMNet *parent)
Definition: mmnet.cpp:280
TModeNet & GetModeNetById(const TInt &ModeId) const
Definition: mmnet.cpp:690
static TStr Fmt(const char *FmtStr,...)
Definition: dt.cpp:1599
TInt Mode1
Definition: mmnet.h:248
TInt Mode2
The first mode. In the case of directed crossnets, this is implicitly understood to be the source mod...
Definition: mmnet.h:249
char * CStr()
Definition: dt.h:476
bool IsKey(const TKey &Key) const
Definition: hash.h:216
TCrossNet & GetCrossNetById(const TInt &CrossId) const
Definition: mmnet.cpp:699
THash< TInt, TStr > CrossIdToNameH
Definition: mmnet.h:532

Here is the call graph for this function:

int TMMNet::DelModeNet ( const TInt ModeId)

Deletes a mode from the multimodal network.

Definition at line 664 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().

664  {
665  TStrV CrossNets;
666  GetModeNetById(ModeId).GetCrossNetNames(CrossNets);
667  for (int i = 0; i < CrossNets.Len(); i++) {
668  if (DelCrossNet(CrossNets[i]) == -1) {
669  return -1;
670  }
671  }
672  TStr ModeName = ModeIdToNameH.GetDat(ModeId);
673  ModeNameToIdH.DelKey(ModeName);
674  ModeIdToNameH.DelKey(ModeId);
675  GetModeNetById(ModeId).SetParentPointer(NULL);
676  TModeNetH.DelKey(ModeId);
677  return 0;
678 }
int DelCrossNet(const TInt &CrossNetId)
Deletes a crossnet from the multimodal network.
Definition: mmnet.cpp:645
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:547
const TDat & GetDat(const TKey &Key) const
Definition: hash.h:220
THash< TInt, TStr > ModeIdToNameH
Definition: mmnet.h:529
void DelKey(const TKey &Key)
Definition: hash.h:362
THash< TStr, TInt > ModeNameToIdH
Definition: mmnet.h:530
void GetCrossNetNames(TStrV &Names) const
Gets a list of CrossNets that have this Mode as either a source or destination type.
Definition: mmnet.h:71
THash< TInt, TModeNet > TModeNetH
Keeps track of the max crossnet id.
Definition: mmnet.h:526
TModeNet & GetModeNetById(const TInt &ModeId) const
Definition: mmnet.cpp:690
Definition: dt.h:412
void SetParentPointer(TMMNet *parent)
Definition: mmnet.cpp:78
Vector is a sequence TVal objects representing an array that can change in size.
Definition: ds.h:429

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 680 of file mmnet.cpp.

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

680  {
681  IAssertR(ModeNameToIdH.IsKey(ModeName), TStr::Fmt("No such mode with name: %s", ModeName.CStr()));
682  return DelModeNet(ModeNameToIdH.GetDat(ModeName));
683 }
#define IAssertR(Cond, Reason)
Definition: bd.h:265
const TDat & GetDat(const TKey &Key) const
Definition: hash.h:220
int DelModeNet(const TInt &ModeId)
Deletes a mode from the multimodal network.
Definition: mmnet.cpp:664
THash< TStr, TInt > ModeNameToIdH
Definition: mmnet.h:530
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:216

Here is the call graph for this function:

TCrossNetI TMMNet::EndCrossNetI ( ) const
inline

Definition at line 591 of file mmnet.h.

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

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

Here is the call graph for this function:

TModeNetI TMMNet::EndModeNetI ( ) const
inline

Definition at line 596 of file mmnet.h.

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

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

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 576 of file mmnet.h.

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

Referenced by ToNetworkMP().

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

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 578 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().

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

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 699 of file mmnet.cpp.

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

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

Here is the caller graph for this function:

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

Gets a reference to the crossnet.

Definition at line 695 of file mmnet.cpp.

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

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

695  {
696  //IAssertR(CrossNameToIdH.IsKey(CrossName),TStr::Fmt("No such link name: %s", CrossName.CStr()));
697  return GetCrossNetById(CrossNameToIdH.GetDat(CrossName));
698 }
const TDat & GetDat(const TKey &Key) const
Definition: hash.h:220
THash< TStr, TInt > CrossNameToIdH
Definition: mmnet.h:533
TCrossNet & GetCrossNetById(const TInt &CrossId) const
Definition: mmnet.cpp:699

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 589 of file mmnet.h.

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

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

Here is the call graph for this function:

int TMMNet::GetCrossNets ( )
inline

Returns the number of crossnets in the multimodal network.

Definition at line 601 of file mmnet.h.

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

601 { return TCrossNetH.Len(); }
THash< TInt, TCrossNet > TCrossNetH
Definition: mmnet.h:527
int Len() const
Definition: hash.h:186

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 572 of file mmnet.h.

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

Referenced by AddCrossNet().

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

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 574 of file mmnet.h.

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

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

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

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 690 of file mmnet.cpp.

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

690  {
691 // IAssertR(ModeId < TModeNetH.Len(), TStr::Fmt("Mode with id %d does not exist", ModeId));
692  TModeNet &Net = (const_cast<TMMNet *>(this))->TModeNetH.GetDat(ModeId);
693  return Net;
694 }
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:468

Here is the caller graph for this function:

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

Gets a reference to the modenet.

Definition at line 685 of file mmnet.cpp.

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

685  {
686  //IAssertR(ModeNameToIdH.IsKey(ModeName),TStr::Fmt("No such mode name: %s", ModeName.CStr()));
687  return GetModeNetById(ModeNameToIdH.GetDat(ModeName));
688 }
const TDat & GetDat(const TKey &Key) const
Definition: hash.h:220
THash< TStr, TInt > ModeNameToIdH
Definition: mmnet.h:530
TModeNet & GetModeNetById(const TInt &ModeId) const
Definition: mmnet.cpp:690

Here is the call graph for this function:

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

Iterator over all modenets.

Definition at line 594 of file mmnet.h.

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

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

Here is the call graph for this function:

int TMMNet::GetModeNets ( )
inline

Returns the number of modes in the multimodal network.

Definition at line 599 of file mmnet.h.

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

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

Here is the call graph for this function:

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

Definition at line 1052 of file mmnet.cpp.

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

Referenced by ToNetworkMP().

1052  {
1053 
1054  TInt PartitionSize = MxLen/NumPartitions;
1055  TInt CurrStart = 0;
1056  bool done = false;
1057  while (!done) {
1058  TInt CurrEnd = CurrStart + PartitionSize;
1059  if (MxLen - CurrEnd < PartitionSize) {
1060  CurrEnd = MxLen;
1061  done = true;
1062  }
1063  Partitions.Add(TIntPr(CurrStart, CurrEnd));
1064  CurrStart = CurrEnd;
1065  }
1066 }
TPair< TInt, TInt > TIntPr
Definition: ds.h:83
Definition: dt.h:1044
TSizeTy Add()
Adds a new element at the end of the vector, after its current last element.
Definition: ds.h:574

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 728 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().

728  {
729  PMMNet Result = New();
730  TInt MxMode = 0;
731  TInt MxCross = 0;
732  TIntH ModeH;
733  for(int i = 0; i < CrossNetTypes.Len(); i++) {
734  TStr CrossName = CrossNetTypes[i];
735  TInt OldId = CrossNameToIdH.GetDat(CrossName);
736  TInt NewId = MxCross++;
737  TCrossNet NewCrossNet(TCrossNetH.GetDat(OldId));
738  TInt OldModeId1 = NewCrossNet.Mode1;
739  TInt OldModeId2 = NewCrossNet.Mode2;
740  TInt NewModeId1, NewModeId2;
741  if (ModeH.IsKey(OldModeId1)) {
742  NewModeId1 = ModeH.GetDat(OldModeId1);
743  } else {
744  NewModeId1 = MxMode++;
745  ModeH.AddDat(OldModeId1, NewModeId1);
746  }
747  if (ModeH.IsKey(OldModeId2)) {
748  NewModeId2 = ModeH.GetDat(OldModeId2);
749  } else {
750  NewModeId2 = MxMode++;
751  ModeH.AddDat(OldModeId2, NewModeId2);
752  }
753  NewCrossNet.Mode1 = NewModeId1;
754  NewCrossNet.Mode2 = NewModeId2;
755  NewCrossNet.CrossNetId = NewId;
756  Result->AddCrossNet(CrossName, NewId, NewCrossNet);
757  }
758  for(TIntH::TIter it = ModeH.BegI(); it < ModeH.EndI(); it++) {
759  TStr ModeName = ModeIdToNameH.GetDat(it.GetKey());
760  TInt NewModeId = it.GetDat();
761  TModeNet NewModeNet;
762  TModeNetH.GetDat(it.GetKey()).RemoveCrossNets(NewModeNet, CrossNetTypes);
763  NewModeNet.ModeId = NewModeId;
764  Result->AddMode(ModeName, NewModeId, NewModeNet);
765  }
766  Result->MxModeId = MxMode;
767  Result->MxCrossNetId = MxCross;
768  return Result;
769 }
TIter BegI() const
Definition: hash.h:171
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:547
const TDat & GetDat(const TKey &Key) const
Definition: hash.h:220
TIter EndI() const
Definition: hash.h:176
THash< TInt, TStr > ModeIdToNameH
Definition: mmnet.h:529
THash< TInt, TCrossNet > TCrossNetH
Definition: mmnet.h:527
TInt ModeId
Definition: mmnet.h:46
THash< TStr, TInt > CrossNameToIdH
Definition: mmnet.h:533
The nodes of one particular mode in a TMMNet, and their neighbor vectors as TIntV attributes...
Definition: mmnet.h:23
Definition: dt.h:1044
THash< TInt, TModeNet > TModeNetH
Keeps track of the max crossnet id.
Definition: mmnet.h:526
static PMMNet New()
Definition: mmnet.h:569
Definition: dt.h:412
Definition: bd.h:196
bool IsKey(const TKey &Key) const
Definition: hash.h:216
TDat & AddDat(const TKey &Key)
Definition: hash.h:196
Implements a single CrossNet consisting of edges between two TModeNets (could be the same TModeNet) ...
Definition: mmnet.h:124

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 771 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.

771  {
772  THash<TInt, TBool> ModeTypeIds;
773  for (int i = 0; i < ModeNetTypes.Len(); i++) {
774  ModeTypeIds.AddDat(ModeNameToIdH.GetDat(ModeNetTypes[i]), true);
775  }
776  TStrV CrossNetTypes;
777  for (THash<TInt, TCrossNet>::TIter it = TCrossNetH.BegI(); it < TCrossNetH.EndI(); it++) {
778  TCrossNet& CrossNet = it.GetDat();
779  if (ModeTypeIds.IsKey(CrossNet.Mode1) && ModeTypeIds.IsKey(CrossNet.Mode2)) {
780  CrossNetTypes.Add(CrossIdToNameH.GetDat(it.GetKey()));
781  ModeTypeIds[CrossNet.Mode1] = false;
782  ModeTypeIds[CrossNet.Mode2] = false;
783  }
784  }
785 
786  PMMNet Result = GetSubgraphByCrossNet(CrossNetTypes);
787  TInt MxMode = Result->MxModeId;
788  TStrV EmptyCrossNetTypes;
789  for (THash<TInt, TBool>::TIter it = ModeTypeIds.BegI(); it < ModeTypeIds.EndI(); it++) {
790  if (it.GetDat().Val) {
791  TStr ModeName = ModeIdToNameH.GetDat(it.GetKey());
792  TInt NewModeId = MxMode++;
793  TModeNet NewModeNet;
794  TModeNetH.GetDat(it.GetKey()).RemoveCrossNets(NewModeNet, EmptyCrossNetTypes);
795  NewModeNet.ModeId = NewModeId;
796  Result->AddMode(ModeName, NewModeId, NewModeNet);
797  }
798  }
799  Result->MxModeId = MxMode;
800  return Result;
801 }
PMMNet GetSubgraphByCrossNet(TStrV &CrossNetTypes)
Gets the induced subgraph given a vector of crossnet type names.
Definition: mmnet.cpp:728
TIter BegI() const
Definition: hash.h:171
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:547
const TDat & GetDat(const TKey &Key) const
Definition: hash.h:220
TIter EndI() const
Definition: hash.h:176
THash< TInt, TStr > ModeIdToNameH
Definition: mmnet.h:529
THash< TInt, TCrossNet > TCrossNetH
Definition: mmnet.h:527
THash< TStr, TInt > ModeNameToIdH
Definition: mmnet.h:530
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:1044
THash< TInt, TModeNet > TModeNetH
Keeps track of the max crossnet id.
Definition: mmnet.h:526
Definition: dt.h:412
Definition: hash.h:88
TInt Mode1
Definition: mmnet.h:248
TInt Mode2
The first mode. In the case of directed crossnets, this is implicitly understood to be the source mod...
Definition: mmnet.h:249
Definition: bd.h:196
bool IsKey(const TKey &Key) const
Definition: hash.h:216
TSizeTy Add()
Adds a new element at the end of the vector, after its current last element.
Definition: ds.h:574
TDat & AddDat(const TKey &Key)
Definition: hash.h:196
Vector is a sequence TVal objects representing an array that can change in size.
Definition: ds.h:429
THash< TInt, TStr > CrossIdToNameH
Definition: mmnet.h:532
Implements a single CrossNet consisting of edges between two TModeNets (could be the same TModeNet) ...
Definition: mmnet.h:124

Here is the call graph for this function:

static PMMNet TMMNet::Load ( TSIn SIn)
inlinestatic

Loads the TMMNet from binary stream.

Definition at line 568 of file mmnet.h.

References TMMNet().

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

Here is the call graph for this function:

static PMMNet TMMNet::New ( )
inlinestatic

Definition at line 569 of file mmnet.h.

References TMMNet().

Referenced by GetSubgraphByCrossNet().

569 { return PMMNet(new TMMNet()); }
TMMNet()
Definition: mmnet.h:540
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 564 of file mmnet.h.

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

564  {MxModeId.Save(SOut); MxCrossNetId.Save(SOut); TModeNetH.Save(SOut);
566  CrossNameToIdH.Save(SOut); }
TInt MxModeId
Definition: mmnet.h:524
void Save(TSOut &SOut) const
Definition: dt.h:1060
void Save(TSOut &SOut) const
Definition: hash.h:141
THash< TInt, TStr > ModeIdToNameH
Definition: mmnet.h:529
THash< TInt, TCrossNet > TCrossNetH
Definition: mmnet.h:527
THash< TStr, TInt > ModeNameToIdH
Definition: mmnet.h:530
THash< TStr, TInt > CrossNameToIdH
Definition: mmnet.h:533
THash< TInt, TModeNet > TModeNetH
Keeps track of the max crossnet id.
Definition: mmnet.h:526
TInt MxCrossNetId
Keeps track of the max mode id.
Definition: mmnet.h:525
THash< TInt, TStr > CrossIdToNameH
Definition: mmnet.h:532

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 803 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.

803  {
804  TIntPrIntH NodeMap;
805  THash<TIntPr, TIntPr> EdgeMap;
806  THashSet<TInt> Modes;
807  PNEANet NewNet = TNEANet::New();
808  //Add nodes and edges
809  for (int i = 0; i < CrossNetTypes.Len(); i++) {
810  TCrossNet& CrossNet = GetCrossNetById(CrossNetTypes[i]);
811  TInt Mode1 = CrossNet.GetMode1();
812  TInt Mode2 = CrossNet.GetMode2();
813  Modes.AddKey(Mode1);
814  Modes.AddKey(Mode2);
815  bool isDirected = CrossNet.IsDirected();
816  for(TCrossNet::TCrossEdgeI EdgeI = CrossNet.BegEdgeI(); EdgeI != CrossNet.EndEdgeI(); EdgeI++) {
817  int srcNode = EdgeI.GetSrcNId();
818  int dstNode = EdgeI.GetDstNId();
819  TIntPr SrcNodeMapping(Mode1, srcNode);
820  int srcId = 0;
821  if (NodeMap.IsKey(SrcNodeMapping)) {
822  srcId = NodeMap.GetDat(SrcNodeMapping);
823  } else {
824  srcId = NewNet->AddNode();
825  NodeMap.AddDat(SrcNodeMapping, srcId);
826  }
827  TIntPr DstNodeMapping(Mode2, dstNode);
828  int dstId = 0;
829  if (NodeMap.IsKey(DstNodeMapping)) {
830  dstId = NodeMap.GetDat(DstNodeMapping);
831  } else {
832  dstId = NewNet->AddNode();
833  NodeMap.AddDat(DstNodeMapping, dstId);
834  }
835  int edgeId = EdgeI.GetId();
836  TIntPr EdgeMapping(CrossNetTypes[i], edgeId);
837  int newEId = NewNet->AddEdge(srcId, dstId);
838  int otherEId = -1;
839  if (!isDirected) {
840  otherEId = NewNet->AddEdge(dstId, srcId);
841  }
842  EdgeMap.AddDat(EdgeMapping, TIntPr(newEId, otherEId));
843  }
844  }
845 
846  for (THashSet<TInt>::TIter it = Modes.BegI(); it != Modes.EndI(); it++) {
847  TModeNet &ModeNet = GetModeNetById(it.GetKey());
848  TInt ModeId = it.GetKey();
849  for(TModeNet::TNodeI NodeIt = ModeNet.BegMMNI(); NodeIt != ModeNet.EndMMNI(); NodeIt++) {
850  TIntPr NodeKey(ModeId, NodeIt.GetId());
851  if (!NodeMap.IsKey(NodeKey)) {
852  int newId = NewNet->AddNode();
853  NodeMap.AddDat(NodeKey, newId);
854  }
855  }
856  }
857 
858  //Add attributes
859  NewNet->AddIntAttrN(TStr("Mode"));
860  NewNet->AddIntAttrN(TStr("Id"));
861  NewNet->AddIntAttrE(TStr("CrossNet"));
862  NewNet->AddIntAttrE(TStr("Id"));
863  for(TIntPrIntH::TIter it = NodeMap.BegI(); it != NodeMap.EndI(); it++) {
864  NewNet->AddIntAttrDatN(it.GetDat(), it.GetKey().GetVal1(), TStr("Mode"));
865  NewNet->AddIntAttrDatN(it.GetDat(), it.GetKey().GetVal2(), TStr("Id"));
866  }
867  for(THash<TIntPr, TIntPr>::TIter it = EdgeMap.BegI(); it != EdgeMap.EndI(); it++) {
868  NewNet->AddIntAttrDatE(it.GetDat().GetVal1(), it.GetKey().GetVal1(), TStr("CrossNet"));
869  NewNet->AddIntAttrDatE(it.GetDat().GetVal1(), it.GetKey().GetVal2(), TStr("Id"));
870  if (it.GetDat().GetVal2() != -1) {
871  NewNet->AddIntAttrDatE(it.GetDat().GetVal2(), it.GetKey().GetVal1(), TStr("CrossNet"));
872  NewNet->AddIntAttrDatE(it.GetDat().GetVal2(), it.GetKey().GetVal2(), TStr("Id"));
873  }
874  }
875 
876  for (int i = 0; i < NodeAttrMap.Len(); i++) {
877  //mode, orig attr, new attr
878  TInt ModeId = NodeAttrMap[i].Val1;
879  TStr OrigAttr = NodeAttrMap[i].Val2;
880  TStr NewAttr = NodeAttrMap[i].Val3;
881  TModeNet& Net = GetModeNetById(ModeId);
882  int type = Net.GetAttrTypeN(OrigAttr);
883  if (type == TModeNet::IntType) {
884  NewNet->AddIntAttrN(NewAttr, Net.GetIntAttrDefaultN(OrigAttr));
885  for(TModeNet::TNodeI it = Net.BegMMNI(); it != Net.EndMMNI(); it++) {
886  TIntPr OldNId(ModeId, it.GetId());
887  int NewId = NodeMap.GetDat(OldNId);
888  int Val = Net.GetIntAttrDatN(it.GetId(), OrigAttr);
889  NewNet->AddIntAttrDatN(NewId, Val, NewAttr);
890  }
891  } else if (type == TModeNet::FltType) {
892  NewNet->AddFltAttrN(NewAttr, Net.GetFltAttrDefaultN(OrigAttr));
893  for(TModeNet::TNodeI it = Net.BegMMNI(); it != Net.EndMMNI(); it++) {
894  TIntPr OldNId(ModeId, it.GetId());
895  int NewId = NodeMap.GetDat(OldNId);
896  TFlt Val = Net.GetFltAttrDatN(it.GetId(), OrigAttr);
897  NewNet->AddFltAttrDatN(NewId, Val, NewAttr);
898  }
899 
900  } else if (type == TModeNet::StrType) {
901  NewNet->AddStrAttrN(NewAttr, Net.GetStrAttrDefaultN(OrigAttr));
902  for(TModeNet::TNodeI it = Net.BegMMNI(); it != Net.EndMMNI(); it++) {
903  TIntPr OldNId(ModeId, it.GetId());
904  int NewId = NodeMap.GetDat(OldNId);
905  TStr Val = Net.GetStrAttrDatN(it.GetId(), OrigAttr);
906  NewNet->AddStrAttrDatN(NewId, Val, NewAttr);
907  }
908  } else if (type == TModeNet::IntVType) {
909  NewNet->AddIntVAttrN(NewAttr);
910  for(TModeNet::TNodeI it = Net.BegMMNI(); it != Net.EndMMNI(); it++) {
911  TIntPr OldNId(ModeId, it.GetId());
912  int NewId = NodeMap.GetDat(OldNId);
913  TIntV Val = Net.GetIntVAttrDatN(it.GetId(), OrigAttr);
914  NewNet->AddIntVAttrDatN(NewId, Val, NewAttr);
915  }
916  }
917  }
918 
919  for (int i = 0; i < EdgeAttrMap.Len(); i++) {
920  //mode, orig attr, new attr
921  TInt CrossId = EdgeAttrMap[i].Val1;
922  TStr OrigAttr = EdgeAttrMap[i].Val2;
923  TStr NewAttr = EdgeAttrMap[i].Val3;
924  TCrossNet& Net = GetCrossNetById(CrossId);
925  int type = Net.GetAttrTypeE(OrigAttr);
926  if (type == TCrossNet::IntType) {
927  NewNet->AddIntAttrE(NewAttr, Net.GetIntAttrDefaultE(OrigAttr));
928  for(TCrossNet::TCrossEdgeI it = Net.BegEdgeI(); it != Net.EndEdgeI(); it++) {
929  TIntPr OldNId(CrossId, it.GetId());
930  TIntPr NewId = EdgeMap.GetDat(OldNId);
931  int Val = Net.GetIntAttrDatE(it.GetId(), OrigAttr);
932  NewNet->AddIntAttrDatE(NewId.Val1, Val, NewAttr);
933  if (NewId.Val2 != -1) {
934  NewNet->AddIntAttrDatE(NewId.Val2, Val, NewAttr);
935  }
936  }
937  } else if (type == TCrossNet::FltType) {
938  NewNet->AddFltAttrE(NewAttr, Net.GetFltAttrDefaultE(OrigAttr));
939  for(TCrossNet::TCrossEdgeI it = Net.BegEdgeI(); it != Net.EndEdgeI(); it++) {
940  TIntPr OldNId(CrossId, it.GetId());
941  TIntPr NewId = EdgeMap.GetDat(OldNId);
942  TFlt Val = Net.GetFltAttrDatE(it.GetId(), OrigAttr);
943  NewNet->AddFltAttrDatE(NewId.Val1, Val, NewAttr);
944  if (NewId.Val2 != -1) {
945  NewNet->AddFltAttrDatE(NewId.Val2, Val, NewAttr);
946  }
947  }
948 
949  } else if (type == TCrossNet::StrType) {
950  NewNet->AddStrAttrE(NewAttr, Net.GetStrAttrDefaultE(OrigAttr));
951  for(TCrossNet::TCrossEdgeI it = Net.BegEdgeI(); it != Net.EndEdgeI(); it++){
952  TIntPr OldNId(CrossId, it.GetId());
953  TIntPr NewId = EdgeMap.GetDat(OldNId);
954  TStr Val = Net.GetStrAttrDatE(it.GetId(), OrigAttr);
955  NewNet->AddStrAttrDatE(NewId.Val1, Val, NewAttr);
956  if (NewId.Val2 != -1) {
957  NewNet->AddStrAttrDatE(NewId.Val2, Val, NewAttr);
958  }
959  }
960  }
961  }
962  return NewNet;
963 }
TStr GetStrAttrDatE(const TCrossEdgeI &EdgeI, const TStr &attr)
Gets the value of str attr from the edge attr value vector.
Definition: mmnet.h:381
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:2304
TStr GetStrAttrDatN(const TNodeI &NodeI, const TStr &attr)
Gets the value of str attr from the node attr value vector.
Definition: network.h:2308
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:171
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:547
TInt GetIntAttrDefaultE(const TStr &attribute) const
Gets Int edge attribute val. If not a proper attr, return default.
Definition: mmnet.h:296
TCrossEdgeI BegEdgeI() const
Definition: mmnet.h:317
Edge iterator. Only forward iteration (operator++) is supported.
Definition: mmnet.h:148
const TDat & GetDat(const TKey &Key) const
Definition: hash.h:220
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:2314
TIter EndI() const
Definition: hash.h:176
TCrossEdgeI EndEdgeI() const
Definition: mmnet.h:318
TFlt GetFltAttrDefaultE(const TStr &attribute) const
Gets Flt edge attribute val. If not a proper attr, return default.
Definition: mmnet.h:300
Definition: dt.h:1293
TNodeI EndMMNI() const
Returns an iterator referring to the past-the-end node in the graph.
Definition: mmnet.h:78
int GetMode2() const
Gets the id of the dst mode.
Definition: mmnet.h:324
TFlt GetFltAttrDatN(const TNodeI &NodeI, const TStr &attr)
Gets the value of flt attr from the node attr value vector.
Definition: network.h:2311
TNodeI BegMMNI() const
Returns an iterator referring to the first node in the graph.
Definition: mmnet.h:76
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:1849
The nodes of one particular mode in a TMMNet, and their neighbor vectors as TIntV attributes...
Definition: mmnet.h:23
Definition: dt.h:1044
TIter EndI() const
Definition: shash.h:1112
Definition: ds.h:32
TModeNet & GetModeNetById(const TInt &ModeId) const
Definition: mmnet.cpp:690
TFlt GetFltAttrDatE(const TCrossEdgeI &EdgeI, const TStr &attr)
Gets the value of flt attr from the edge attr value vector.
Definition: mmnet.h:384
Definition: dt.h:412
int GetMode1() const
Gets the id of the src mode.
Definition: mmnet.h:322
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:1851
TInt GetIntAttrDefaultN(const TStr &attribute) const
Gets Int node attribute val. If not a proper attr, return default.
Definition: network.h:1847
bool IsKey(const TKey &Key) const
Definition: hash.h:216
static PNEANet New()
Static cons returns pointer to graph. Ex: PNEANet Graph=TNEANet::New().
Definition: network.h:1940
TDat & AddDat(const TKey &Key)
Definition: hash.h:196
TCrossNet & GetCrossNetById(const TInt &CrossId) const
Definition: mmnet.cpp:699
TInt GetIntAttrDatE(const TCrossEdgeI &EdgeI, const TStr &attr)
Gets the value of int attr from the edge attr value vector.
Definition: mmnet.h:378
bool IsDirected() const
Whether edges in the crossnet are directed.
Definition: mmnet.h:331
int GetAttrTypeN(const TStr &attr) const
Definition: mmnet.cpp:159
int GetAttrTypeE(const TStr &attr) const
Definition: mmnet.cpp:167
TStr GetStrAttrDefaultE(const TStr &attribute) const
Gets Str edge attribute val. If not a proper attr, return default.
Definition: mmnet.h:298
Implements a single CrossNet consisting of edges between two TModeNets (could be the same TModeNet) ...
Definition: mmnet.h:124

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 965 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().

965  {
966  TIntPrIntH NodeMap;
967  THashSet<TInt> Modes;
968  PNEANet NewNet = TNEANet::New();
969  NewNet->AddIntAttrN(TStr("Mode"));
970  NewNet->AddIntAttrN(TStr("Id"));
971  NewNet->AddIntAttrE(TStr("CrossNet"));
972  NewNet->AddIntAttrE(TStr("Id"));
973 
974  //Add nodes and edges
975  for (int i = 0; i < CrossNetTypes.Len(); i++) {
976  TCrossNet& CrossNet = GetCrossNetById(CrossNetTypes[i]);
977  TStrPrV CNetAttrs;
978  if (EdgeAttrMap.IsKey(CrossNetTypes[i])) {
979  CNetAttrs = EdgeAttrMap.GetDat(CrossNetTypes[i]);
980  }
981  TInt Mode1 = CrossNet.GetMode1();
982  TInt Mode2 = CrossNet.GetMode2();
983  TModeNet& Mode1Net = GetModeNetById(Mode1);
984  TModeNet& Mode2Net = GetModeNetById(Mode2);
985  TStrPrV Mode1Attrs;
986  if (NodeAttrMap.IsKey(Mode1)) {
987  Mode1Attrs = NodeAttrMap.GetDat(Mode1);
988  }
989  TStrPrV Mode2Attrs;
990  if (NodeAttrMap.IsKey(Mode2)) {
991  Mode2Attrs = NodeAttrMap.GetDat(Mode2);
992  }
993  Modes.AddKey(Mode1);
994  Modes.AddKey(Mode2);
995  bool isDirected = CrossNet.IsDirected();
996  for(TCrossNet::TCrossEdgeI EdgeI = CrossNet.BegEdgeI(); EdgeI != CrossNet.EndEdgeI(); EdgeI++) {
997  int srcNode = EdgeI.GetSrcNId();
998  int dstNode = EdgeI.GetDstNId();
999  TIntPr SrcNodeMapping(Mode1, srcNode);
1000  int srcId = 0;
1001  if (NodeMap.IsKey(SrcNodeMapping)) {
1002  srcId = NodeMap.GetDat(SrcNodeMapping);
1003  } else {
1004  srcId = NewNet->AddNode();
1005  NodeMap.AddDat(SrcNodeMapping, srcId);
1006  NewNet->AddIntAttrDatN(srcId, srcNode, TStr("Id"));
1007  NewNet->AddIntAttrDatN(srcId, Mode1, TStr("Mode"));
1008  AddNodeAttributes(NewNet, Mode1Net, Mode1Attrs, Mode1, srcNode, srcId);
1009  }
1010  TIntPr DstNodeMapping(Mode2, dstNode);
1011  int dstId = 0;
1012  if (NodeMap.IsKey(DstNodeMapping)) {
1013  dstId = NodeMap.GetDat(DstNodeMapping);
1014  } else {
1015  dstId = NewNet->AddNode();
1016  NodeMap.AddDat(DstNodeMapping, dstId);
1017  NewNet->AddIntAttrDatN(dstId, dstNode, TStr("Id"));
1018  NewNet->AddIntAttrDatN(dstId, Mode2, TStr("Mode"));
1019  AddNodeAttributes(NewNet, Mode2Net, Mode2Attrs, Mode2, dstNode, dstId);
1020  }
1021  int edgeId = EdgeI.GetId();
1022  int newEId = NewNet->AddEdge(srcId, dstId);
1023  NewNet->AddIntAttrDatE(newEId, edgeId, TStr("Id"));
1024  NewNet->AddIntAttrDatE(newEId, CrossNetTypes[i], TStr("CrossNet"));
1025  AddEdgeAttributes(NewNet, CrossNet, CNetAttrs, CrossNetTypes[i], edgeId, newEId);
1026  if (!isDirected) {
1027  int otherEId = NewNet->AddEdge(dstId, srcId);
1028  NewNet->AddIntAttrDatE(otherEId, edgeId, TStr("Id"));
1029  NewNet->AddIntAttrDatE(otherEId, CrossNetTypes[i], TStr("CrossNet"));
1030  AddEdgeAttributes(NewNet, CrossNet, CNetAttrs, CrossNetTypes[i], edgeId, otherEId);
1031  }
1032  }
1033  }
1034 
1035  for (THashSet<TInt>::TIter it = Modes.BegI(); it != Modes.EndI(); it++) {
1036  TInt ModeId = it.GetKey();
1037  TModeNet &ModeNet = GetModeNetById(ModeId);
1038  TStrPrV ModeAttrs = NodeAttrMap.GetDat(ModeId);
1039  for(TModeNet::TNodeI NodeIt = ModeNet.BegMMNI(); NodeIt != ModeNet.EndMMNI(); NodeIt++) {
1040  TIntPr NodeKey(ModeId, NodeIt.GetId());
1041  if (!NodeMap.IsKey(NodeKey)) {
1042  int newId = NewNet->AddNode();
1043  NodeMap.AddDat(NodeKey, newId);
1044  AddNodeAttributes(NewNet, ModeNet, ModeAttrs, ModeId, NodeIt.GetId(), newId);
1045  }
1046  }
1047  }
1048 
1049  return NewNet;
1050 }
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:547
TCrossEdgeI BegEdgeI() const
Definition: mmnet.h:317
Edge iterator. Only forward iteration (operator++) is supported.
Definition: mmnet.h:148
const TDat & GetDat(const TKey &Key) const
Definition: hash.h:220
TCrossEdgeI EndEdgeI() const
Definition: mmnet.h:318
TNodeI EndMMNI() const
Returns an iterator referring to the past-the-end node in the graph.
Definition: mmnet.h:78
int GetMode2() const
Gets the id of the dst mode.
Definition: mmnet.h:324
TNodeI BegMMNI() const
Returns an iterator referring to the first node in the graph.
Definition: mmnet.h:76
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:1249
The nodes of one particular mode in a TMMNet, and their neighbor vectors as TIntV attributes...
Definition: mmnet.h:23
Definition: dt.h:1044
TIter EndI() const
Definition: shash.h:1112
Definition: ds.h:32
TModeNet & GetModeNetById(const TInt &ModeId) const
Definition: mmnet.cpp:690
Definition: dt.h:412
int GetMode1() const
Gets the id of the src mode.
Definition: mmnet.h:322
Definition: bd.h:196
bool IsKey(const TKey &Key) const
Definition: hash.h:216
int AddEdgeAttributes(PNEANet &NewNet, TCrossNet &Net, TVec< TPair< TStr, TStr > > &Attrs, int CrossId, int oldId, int EId)
Definition: mmnet.cpp:1276
static PNEANet New()
Static cons returns pointer to graph. Ex: PNEANet Graph=TNEANet::New().
Definition: network.h:1940
TDat & AddDat(const TKey &Key)
Definition: hash.h:196
TCrossNet & GetCrossNetById(const TInt &CrossId) const
Definition: mmnet.cpp:699
bool IsDirected() const
Whether edges in the crossnet are directed.
Definition: mmnet.h:331
Vector is a sequence TVal objects representing an array that can change in size.
Definition: ds.h:429
Implements a single CrossNet consisting of edges between two TModeNets (could be the same TModeNet) ...
Definition: mmnet.h:124

Here is the call graph for this function:

PNEANetMP TMMNet::ToNetworkMP ( TStrV CrossNetNames)

Definition at line 1070 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.

1070  {
1071 
1072  TStrIntH CrossNetStart;
1073  THashSet<TInt> ModeSet;
1074  int offset = 0;
1075  int NumEdges = 0;
1076  for (int i=0; i < CrossNetNames.Len(); i++) {
1077  CrossNetStart.AddDat(CrossNetNames[i], offset);
1078  TCrossNet& CrossNet = GetCrossNetByName(CrossNetNames[i]);
1079  int factor = CrossNet.IsDirected() ? 1 : 2;
1080  offset += (CrossNet.GetMxEId() * factor);
1081  NumEdges += (CrossNet.GetEdges() * factor);
1082  ModeSet.AddKey(CrossNet.GetMode1());
1083  ModeSet.AddKey(CrossNet.GetMode2());
1084  }
1085  int MxEId = offset;
1086 
1087  int NumNodes = 0;
1088  for (THashSet<TInt>::TIter MI = ModeSet.BegI(); MI < ModeSet.EndI(); MI++) {
1089  TModeNet& ModeNet = GetModeNetById(MI.GetKey());
1090  NumNodes += ModeNet.GetNodes();
1091  }
1092 
1093  THashMP<TIntPr, TInt> NodeMap(NumNodes);
1094  THashMP<TIntPr, TIntPr> EdgeMap(NumEdges);
1095  PNEANetMP NewNet = TNEANetMP::New(NumNodes, NumEdges);
1096 
1097  int num_threads = omp_get_max_threads();
1098  offset = 0;
1099  for (THashSet<TInt>::TIter MI = ModeSet.BegI(); MI < ModeSet.EndI(); MI++) {
1100  TInt ModeId = MI.GetKey();
1101  TModeNet& ModeNet = GetModeNetById(ModeId);
1102  TIntV KeyIds;
1103  ModeNet.NodeH.GetKeyV(KeyIds);
1104 
1105  TIntPrV NodePartitions;
1106  GetPartitionRanges(NodePartitions, num_threads, KeyIds.Len());
1107 
1108  int curr_nid;
1109  #pragma omp parallel for schedule(static) private(curr_nid)
1110  for (int i = 0; i < NodePartitions.Len(); i++) {
1111  TInt CurrStart = NodePartitions[i].GetVal1();
1112  TInt CurrEnd = NodePartitions[i].GetVal2();
1113  curr_nid = offset + CurrStart;
1114  for (int idx = CurrStart; idx < CurrEnd ; idx++) {
1115  int n_i = KeyIds[idx];
1116  if (ModeNet.IsNode(n_i)) {
1117  //Collect neighbors
1118  TIntV InNbrs;
1119  TIntV OutNbrs;
1120  for (int j=0; j < CrossNetNames.Len(); j++) {
1121  if (ModeNet.NeighborTypes.IsKey(CrossNetNames[j])) {
1122  if (ModeNet.NeighborTypes.GetDat(CrossNetNames[j])) {
1123 
1124  TIntV Neighbors;
1125  ModeNet.GetNeighborsByCrossNet(n_i, CrossNetNames[j], Neighbors);
1126  int edge_offset = CrossNetStart.GetDat(CrossNetNames[j]);
1127  TCrossNet CrossNet = GetCrossNetByName(CrossNetNames[j]);
1128  bool isDir = CrossNet.IsDirected();
1129  bool isOutNbr = CrossNet.GetMode1() == ModeId;
1130  int factor = isDir ? 1 : 2;
1131 
1132  int id_offset = isDir || isOutNbr ? 0 : 1;
1133  if (!isDir && CrossNet.GetMode1() == CrossNet.GetMode2()) {
1134  id_offset = n_i == CrossNet.GetEdge(n_i).GetSrcNId() ? 0 : 1;
1135  }
1136 
1137  for (int k = 0; k < Neighbors.Len(); k++) {
1138  if (isOutNbr && id_offset == 0) {
1139  OutNbrs.Add(edge_offset + Neighbors[k]*factor + id_offset);
1140  } else {
1141  InNbrs.Add(edge_offset + Neighbors[k]*factor + id_offset);
1142  }
1143  if (!isDir) {
1144  int opp_offset = id_offset == 1 ? 0 : 1;
1145  if (isOutNbr && id_offset == 0) {
1146  InNbrs.Add(edge_offset + Neighbors[k]*factor + opp_offset);
1147  } else {
1148  OutNbrs.Add(edge_offset + Neighbors[k]*factor + opp_offset);
1149  }
1150  }
1151  }
1152  } else {
1153  TIntV TempOut;
1154  ModeNet.GetNeighborsByCrossNet(n_i, CrossNetNames[j], TempOut, true);
1155  OutNbrs.AddV(TempOut);
1156  TIntV TempIn;
1157  ModeNet.GetNeighborsByCrossNet(n_i, CrossNetNames[j], TempIn, false);
1158  InNbrs.AddV(TempIn);
1159  }
1160  }
1161  }
1162 
1163  NewNet->AddNodeWithEdges(curr_nid, InNbrs, OutNbrs);
1164  TIntPr NodeKey(MI.GetKey(), n_i);
1165  NodeMap.AddDat(NodeKey, curr_nid);
1166  curr_nid++;
1167  }
1168  }
1169  }
1170  offset += KeyIds.Len();
1171  }
1172  NewNet->SetNodes(offset);
1173 
1174  for (int j=0; j < CrossNetNames.Len(); j++) {
1175  TStr CrossNetName = CrossNetNames[j];
1176  TCrossNet& CrossNet = GetCrossNetByName(CrossNetName);
1177  TInt CrossNetId = GetCrossId(CrossNetName);
1178  TInt Mode1 = CrossNet.GetMode1();
1179  TInt Mode2 = CrossNet.GetMode2();
1180 
1181  TIntPrV EdgePartitions;
1182  GetPartitionRanges(EdgePartitions, num_threads, CrossNet.MxEId);
1183  int curr_eid;
1184  offset = CrossNetStart.GetDat(CrossNetNames[j]);
1185  int factor = CrossNet.IsDirected() ? 1 : 2;
1186  #pragma omp parallel for schedule(static) private(curr_eid)
1187  for (int i = 0; i < EdgePartitions.Len(); i++) {
1188  TInt CurrStart = EdgePartitions[i].GetVal1();
1189  TInt CurrEnd = EdgePartitions[i].GetVal2();
1190  for (int e_i = CurrStart; e_i < CurrEnd ; e_i++) {
1191  curr_eid = offset + factor*e_i;
1192  if (CrossNet.IsEdge(e_i)) {
1193  int new_eid = curr_eid;
1194  TIntPr EdgeKey(CrossNetId, e_i);
1195  TCrossNet::TCrossEdgeI edge = CrossNet.GetEdgeI(e_i);
1196  int srcNode = edge.GetSrcNId();
1197  int dstNode = edge.GetDstNId();
1198  TIntPr NodeKeySrc(Mode1, srcNode);
1199  TIntPr NodeKeyDst(Mode2, dstNode);
1200  int newSrc = NodeMap.GetDat(NodeKeySrc);
1201  int newDst = NodeMap.GetDat(NodeKeyDst);
1202  NewNet->AddEdgeUnchecked(curr_eid, newSrc, newDst);
1203  curr_eid++;
1204  int otherEId = -1;
1205  if (!CrossNet.IsDirected()) {
1206  otherEId = curr_eid;
1207  NewNet->AddEdgeUnchecked(otherEId, newDst, newSrc);
1208  }
1209  EdgeMap.AddDat(EdgeKey, TIntPr(new_eid, otherEId));
1210  }
1211  }
1212  }
1213  }
1214  NewNet->SetEdges(MxEId);
1215  NewNet->ReserveAttr(2, 0, 0, 2, 0, 0);
1216 
1217  //Add attributes
1218  NewNet->AddIntAttrN(TStr("Mode"));
1219  NewNet->AddIntAttrN(TStr("Id"));
1220  NewNet->AddIntAttrE(TStr("CrossNet"));
1221  NewNet->AddIntAttrE(TStr("Id"));
1222 
1223  TIntPrV NewNodeIds;
1224  NodeMap.GetKeyV(NewNodeIds);
1225 
1226  #pragma omp parallel for schedule(static)
1227  for(int i = 0; i < NewNodeIds.Len(); i++) {
1228  NewNet->AddIntAttrDatN(NodeMap.GetDat(NewNodeIds[i]), NewNodeIds[i].GetVal1(), TStr("Mode"));
1229  NewNet->AddIntAttrDatN(NodeMap.GetDat(NewNodeIds[i]), NewNodeIds[i].GetVal2(), TStr("Id"));
1230  }
1231 
1232 
1233  TIntPrV NewEdgeIds;
1234  EdgeMap.GetKeyV(NewEdgeIds);
1235  #pragma omp parallel for schedule(static)
1236  for(int i = 0; i < NewEdgeIds.Len(); i++) {
1237  NewNet->AddIntAttrDatE(EdgeMap.GetDat(NewEdgeIds[i]).GetVal1(), NewEdgeIds[i].GetVal2(), TStr("Id"));
1238  NewNet->AddIntAttrDatE(EdgeMap.GetDat(NewEdgeIds[i]).GetVal1(), NewEdgeIds[i].GetVal1(), TStr("CrossNet"));
1239  if (EdgeMap.GetDat(NewEdgeIds[i]).GetVal2() != -1) {
1240  NewNet->AddIntAttrDatE(EdgeMap.GetDat(NewEdgeIds[i]).GetVal2(), NewEdgeIds[i].GetVal1(), TStr("CrossNet"));
1241  NewNet->AddIntAttrDatE(EdgeMap.GetDat(NewEdgeIds[i]).GetVal2(), NewEdgeIds[i].GetVal2(), TStr("Id"));
1242  }
1243  }
1244  return NewNet;
1245 }
TPair< TInt, TInt > TIntPr
Definition: ds.h:83
int GetNodes() const
Returns the number of nodes in the graph.
Definition: network.h:1969
void GetPartitionRanges(TIntPrV &Partitions, const TInt &NumPartitions, const TInt &MxVal) const
Definition: mmnet.cpp:1052
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:165
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:547
Edge iterator. Only forward iteration (operator++) is supported.
Definition: mmnet.h:148
const TDat & GetDat(const TKey &Key) const
Definition: hash.h:220
TCrossEdge & GetEdge(int eid)
Definition: mmnet.h:302
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:106
int GetMode2() const
Gets the id of the dst mode.
Definition: mmnet.h:324
int GetSrcNId() const
Definition: mmnet.h:142
int AddKey(const TKey &Key)
Definition: shash.h:1254
int GetDstNId() const
Returns the destination of the edge.
Definition: mmnet.h:167
The nodes of one particular mode in a TMMNet, and their neighbor vectors as TIntV attributes...
Definition: mmnet.h:23
Definition: dt.h:1044
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:309
TModeNet & GetModeNetById(const TInt &ModeId) const
Definition: mmnet.cpp:690
int GetMxEId() const
Definition: mmnet.h:307
void GetKeyV(TVec< TKey > &KeyV) const
Definition: hash.h:442
Definition: dt.h:412
TCrossEdgeI GetEdgeI(const int &EId) const
Edge iterators.
Definition: mmnet.h:316
int GetCrossId(const TStr &CrossName) const
Gets the crossnet id from the crossnet name.
Definition: mmnet.h:576
int GetMode1() const
Gets the id of the src mode.
Definition: mmnet.h:322
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:1985
THash< TInt, TNode > NodeH
Definition: network.h:1862
bool IsEdge(const int &EId) const
Tests whether an edge with edge ID EId exists in the graph.
Definition: mmnet.h:305
TInt MxEId
The HashTable from Edge id to the corresponding Edge.
Definition: mmnet.h:247
bool IsKey(const TKey &Key) const
Definition: hash.h:216
TCrossNet & GetCrossNetByName(const TStr &CrossName) const
Gets a reference to the crossnet.
Definition: mmnet.cpp:695
TSizeTy Add()
Adds a new element at the end of the vector, after its current last element.
Definition: ds.h:574
TDat & AddDat(const TKey &Key)
Definition: hash.h:196
bool IsDirected() const
Whether edges in the crossnet are directed.
Definition: mmnet.h:331
TSizeTy AddV(const TVec< TVal, TSizeTy > &ValV)
Adds the elements of the vector ValV to the to end of the vector.
Definition: ds.h:1056
Implements a single CrossNet consisting of edges between two TModeNets (could be the same TModeNet) ...
Definition: mmnet.h:124

Here is the call graph for this function:

Friends And Related Function Documentation

friend class TCrossNet
friend

Definition at line 536 of file mmnet.h.

Referenced by AddCrossNet().

friend class TModeNet
friend

Definition at line 537 of file mmnet.h.

Member Data Documentation

TCRef TMMNet::CRef

Definition at line 520 of file mmnet.h.

THash<TInt,TStr> TMMNet::CrossIdToNameH
private

Definition at line 532 of file mmnet.h.

Referenced by AddCrossNet(), ClrNbr(), DelCrossNet(), GetCrossName(), GetSubgraphByModeNet(), and Save().

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 525 of file mmnet.h.

Referenced by AddCrossNet(), and Save().

TInt TMMNet::MxModeId
private

Definition at line 524 of file mmnet.h.

Referenced by AddModeNet(), and Save().

THash<TInt, TModeNet> TMMNet::TModeNetH
private

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