Exemple #1
0
 int FindCascadeRoot(const PGraph& G, const TIntH& NIdInfTmH) { // earliest infected node
   int Min=TInt::Mx, MinNId=-1;
   for (typename PGraph::TObj::TNodeI NI = G->BegNI(); NI < G->EndNI(); NI++) {
     const int t = NIdInfTmH.GetDat(NI.GetId());
     if (t < Min && NI.GetInDeg()==0) { Min=t; MinNId=NI.GetId(); } }
   IAssert(MinNId!=-1);  return MinNId;
 }
Exemple #2
0
 double GetAvgDepthFromRoot(const PGraph& G) {
   TMom Mom;
   TIntPrV HopCntV;
   for (typename PGraph::TObj::TNodeI NI = G->BegNI(); NI < G->EndNI(); NI++) {
     if (NI.GetOutDeg()>0 && NI.GetInDeg()==0) {
       TSnap::GetNodesAtHops(G, NI.GetId(), HopCntV, true);
       Mom.Add(HopCntV.Last().Val1()); }
   }
   Mom.Def();  return Mom.GetMean();
 }
Exemple #3
0
 void SampleCascade(const PGraph& InfCasc, const PGraph& NetCasc, const TIntH& NIdInfTmH, const double& PStep=0.05, const int& NRuns=1, const bool& DivByM=true) {
   for (int Run=0; Run < NRuns; Run++) {
     for (double P = PStep; P <= 1.01; P += PStep) {
       TIntV NIdV;
       for (typename PGraph::TObj::TNodeI NI = InfCasc->BegNI(); NI < InfCasc->EndNI(); NI++) {
         if (TInt::Rnd.GetUniDev() < P) { NIdV.Add(NI.GetId()); } }
       PGraph InfG = TSnap::GetSubGraph(InfCasc, NIdV);
       PGraph NetG = TSnap::GetSubGraph(NetCasc, NIdV);
       if (InfG->GetNodes()==0) { continue; }
       TakeStat(InfG, NetG, NIdInfTmH, P, DivByM);
     }
   }
 }