SNAP Library , Developer Reference  2013-01-07 14:03:36
SNAP, a general purpose, high performance system for analysis and manipulation of large networks
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
timenet.h
Go to the documentation of this file.
00001 
00002 // Forward declarations
00003 class TGrowthStat;
00004 typedef TPt<TGrowthStat> PGrowthStat;
00005 class TGStatVec;
00006 typedef TPt<TGStatVec> PGStatVec;
00007 
00008 class TTimeNet;
00009 typedef TPt<TTimeNet> PTimeNet;
00010 
00011 class TTimeNENet;
00012 typedef TPt<TTimeNENet> PTimeNENet;
00013 
00015 // Time Network
00016 class TTimeNet : public TNodeNet<TSecTm> {
00017 public:
00018   typedef TNodeNet<TSecTm> TNet;
00019   typedef TPt<TNodeNet<TSecTm> > PNet;
00020 public:
00021   class TTmBucket {
00022   public:
00023     TSecTm BegTm; // start time of the bucket, end time is determined by GroupBy
00024     TIntV NIdV;
00025   public:
00026     TTmBucket() { }
00027     TTmBucket(const TSecTm& BucketTm) : BegTm(BucketTm) { }
00028     TTmBucket(const TTmBucket& TmBucket) : BegTm(TmBucket.BegTm), NIdV(TmBucket.NIdV) { }
00029     TTmBucket& operator = (const TTmBucket& TmBucket) { if (this!=&TmBucket) {
00030       BegTm=TmBucket.BegTm; NIdV=TmBucket.NIdV; } return *this; }
00031   };
00032   typedef TVec<TTmBucket> TTmBucketV;
00033 public:
00034   TTimeNet() { }
00035   TTimeNet(const int& Nodes, const int& Edges) : TNet(Nodes, Edges) { }
00036   TTimeNet(const TTimeNet& TimeNet) : TNet(TimeNet) { }
00037   TTimeNet(TSIn& SIn) : TNet(SIn) { }
00038   void Save(TSOut& SOut) const { TNet::Save(SOut); }
00039   static PTimeNet New() { return new TTimeNet(); }
00040   static PTimeNet New(const int& Nodes, const int& Edges) { return new TTimeNet(Nodes, Edges); }
00041   static PTimeNet Load(TSIn& SIn) { return new TTimeNet(SIn); }
00042   TTimeNet& operator = (const TTimeNet& TimeNet);
00043 
00044   PTimeNet GetSubGraph(const TIntV& NIdV) const;
00045   PTimeNENet GetTimeNENet() const;
00046 
00047   void GetNIdByTm(TIntV& NIdV) const;
00048   void GetTmBuckets(const TTmUnit& GroupBy, TTmBucketV& TmBucketV) const;
00049   void GetNodeBuckets(const int NodesPerBucket, TTimeNet::TTmBucketV& TmBucketV) const;
00050 
00051   PGStatVec TimeGrowth(const TTmUnit& TmUnit, const TFSet& TakeStat, const TSecTm& StartTm) const;
00052   void PlotEffDiam(const TStr& FNmPref, const TStr& Desc, const TTmUnit& GroupBy, const TSecTm& StartTm,
00053     const int& NDiamRuns=10, const bool& OnlyWcc=false, const bool& AlsoRewire=false) const;
00054   void PlotMissingPast(const TStr& FNmPref, const TStr& Desc, const TTmUnit& GroupBy,
00055     const TSecTm& DelPreTmEdges, const TSecTm& PostTmDiam) const;
00056   void PlotCCfOverTm(const TStr& FNmPref, TStr Desc, const TTmUnit& TmUnit, const int& NodesBucket=-1) const;
00057   void PlotMedianDegOverTm(const TStr& FNmPref, const TTmUnit& TmUnit, const int& NodesPerBucket=-1) const;
00058 
00059   // networks
00060   static PTimeNet LoadBipartite(const TStr& InFNm);
00061   static PTimeNet LoadArxiv(const TStr& PaperFNm, const TStr& CiteFNm);
00062   static PTimeNet LoadPatents(const TStr& PatentFNm, const TStr& CiteFNm);
00063   static PTimeNet LoadAmazon(const TStr& StlFNm);
00064 
00065   friend class TPt<TTimeNet>;
00066 };
00067 
00068 // set flags
00069 namespace TSnap {
00070 template <> struct IsDirected<TTimeNet> { enum { Val = 1 }; };
00071 template <> struct IsNodeDat<TTimeNet> { enum { Val = 1 }; };
00072 }
00073 
00075 // Time Node-Edge Network
00076 class TTimeNENet : public TNodeEdgeNet<TSecTm, TSecTm> {
00077 public:
00078   typedef TNodeEdgeNet<TSecTm, TSecTm> TNet;
00079   typedef TPt<TNodeEdgeNet<TSecTm, TSecTm> > PNet;
00080 public:
00081   TTimeNENet() { }
00082   TTimeNENet(const int& Nodes, const int& Edges) : TNet(Nodes, Edges) { }
00083   TTimeNENet(TSIn& SIn) : TNet(SIn) { }
00084   TTimeNENet(const TTimeNENet& TimeNet) : TNet(TimeNet) { }
00085   void Save(TSOut& SOut) const { TNet::Save(SOut); }
00086   static PTimeNENet New() { return new TTimeNENet(); }
00087   static PTimeNENet New(const int& Nodes, const int& Edges) { return new TTimeNENet(Nodes, Edges); }
00088   static PTimeNENet Load(TSIn& SIn) { return new TTimeNENet(SIn); }
00089   TTimeNENet& operator = (const TTimeNENet& TimeNet);
00090 
00091   PTimeNet GetTimeNet() const;
00092   PTimeNENet Get1stEdgeNet() const;
00093   PTimeNENet GetSubGraph(const TIntV& NIdV) const;
00094   PTimeNENet GetESubGraph(const TIntV& EIdV) const;
00095   PTimeNENet GetGraphUpToTm(const TSecTm& MaxEdgeTm) const;
00096 
00097   void SortNodeEdgeTimes();
00098   void UpdateNodeTimes();
00099   void SetNodeTmToFirstEdgeTm();
00100   void SetRndEdgeTimes(const int& MinTmEdge=0);
00101   void DumpTimeStat() const;
00102 
00103   void GetNIdByTm(TIntV& NIdV) const;
00104   void GetEIdByTm(TIntV& EIdV) const;
00105   void GetTmBuckets(const TTmUnit& GroupBy, TTimeNet::TTmBucketV& TmBucketV) const;
00106   void GetEdgeTmBuckets(const TTmUnit& GroupBy, TTimeNet::TTmBucketV& TmBucketV) const;
00107   void GetNodeBuckets(const int NodesPerBucket, TTimeNet::TTmBucketV& TmBucketV) const;
00108   void GetEdgeBuckets(const int EdgesPerBucket, TTimeNet::TTmBucketV& TmBucketV) const;
00109   int GetTriadEdges(TIntV& TriadEIdV) const;
00110 
00111   PGStatVec TimeGrowth(const TTmUnit& TimeStep, const TFSet& TakeStat, const TSecTm& StartTm=TSecTm(1)) const;
00112   PGStatVec TimeGrowth(const TStr& FNmPref, const TStr& Desc, const TFSet& TakeStat, const int& NDiamRuns,
00113     const TTmUnit& TmUnit, const int& TakeNTmUnits, const bool& LinkBWays) const;
00114   void PlotEffDiam(const TStr& FNmPref, const TStr& Desc, const TTmUnit& GroupBy, const TSecTm& StartTm,
00115     const int& NDiamRuns=10, const bool& OnlyWcc=false) const;
00116   void PlotMissingPast(const TStr& FNmPref, const TStr& Desc, const TTmUnit& TmUnit,
00117     const TSecTm& DelPreTmEdges, const TSecTm& PostTmDiam, const bool& LinkBWays);
00118 
00119   void SaveEdgeTm(const TStr& EdgeFNm, const bool& RenumberNId=false, const bool& RelativeTm=false) const;
00120   static PTimeNENet GetSmallNet();
00121   static PTimeNENet GetGnmRndNet(const int& Nodes, const int& Edges);
00122   static PTimeNENet GetPrefAttach(const int& Nodes, const int& Edges, const double& GammaIn, const double& GammaOut);
00123   static PTimeNENet GetPrefAttach(const int& Nodes, const int& OutDeg);
00124   static PTimeNENet LoadFlickr(const TStr& NodeFNm, const TStr& EdgeFNm);
00125   static PTimeNENet LoadEdgeTm(const TStr& EdgeFNm, const int& SrcFld=0, const int& DstFld=1, const int& TimeFld=2, const TSsFmt& Separator=ssfTabSep);
00126 
00127   friend class TPt<TTimeNENet>;
00128 };
00129 
00130 // set flags
00131 namespace TSnap {
00132 template <> struct IsMultiGraph<TTimeNENet> { enum { Val = 1 }; };
00133 template <> struct IsDirected<TTimeNENet> { enum { Val = 1 }; };
00134 template <> struct IsNodeDat<TTimeNENet> { enum { Val = 1 }; };
00135 template <> struct IsEdgeDat<TTimeNENet> { enum { Val = 1 }; };
00136 }