当前位置: 首页>>代码示例>>C++>>正文


C++ TIntH::GetDat方法代码示例

本文整理汇总了C++中TIntH::GetDat方法的典型用法代码示例。如果您正苦于以下问题:C++ TIntH::GetDat方法的具体用法?C++ TIntH::GetDat怎么用?C++ TIntH::GetDat使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在TIntH的用法示例。


在下文中一共展示了TIntH::GetDat方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: FindAugV

/// Returns the amount the flow can be augmented over the paths, 0 if no path can be found. ##TSnap::FindAugV
int FindAugV (const PNEANet &Net, const int& CapIndex, TIntV &Flow, TIntQ &FwdNodeQ, TIntH &PredEdgeH, TIntQ &BwdNodeQ, TIntH &SuccEdgeH, TIntV &MidToSrcAugV, TIntV &MidToSnkAugV, const int& SrcNId, const int& SnkNId) {
  int MidPtNId = IntFlowBiDBFS(Net, CapIndex, Flow, FwdNodeQ, PredEdgeH, BwdNodeQ, SuccEdgeH, SrcNId, SnkNId);
  if (MidPtNId == -1) { return 0; }
  int MinAug = TInt::Mx, NId = MidPtNId, AugFlow = 0;
  // Build the path from the midpoint back to the source by tracing through the PredEdgeH
  for (int EId = PredEdgeH.GetDat(NId); NId != SrcNId; EId = PredEdgeH.GetDat(NId)) {
    MidToSrcAugV.Add(EId);
    const TNEANet::TEdgeI &EI = Net->GetEI(EId);
    if (EI.GetSrcNId() == NId) {
      NId = EI.GetDstNId();
      AugFlow = Flow[EId];
    } else {
      NId = EI.GetSrcNId();
      AugFlow = Net->GetIntAttrIndDatE(EId, CapIndex) - Flow[EId];
    }
    if (AugFlow < MinAug) { MinAug = AugFlow; }
  }
  NId = MidPtNId;
  // Build the path from the midpoint back to the sink by tracing through the SuccEdgeH
  for (int EId = SuccEdgeH.GetDat(NId); NId != SnkNId; EId = SuccEdgeH.GetDat(NId)) {
    MidToSnkAugV.Add(EId);
    const TNEANet::TEdgeI &EI = Net->GetEI(EId);
    if (EI.GetDstNId() == NId) {
      NId = EI.GetSrcNId();
      AugFlow = Flow[EId];
    } else {
      NId = EI.GetDstNId();
      AugFlow = Net->GetIntAttrIndDatE(EId, CapIndex) - Flow[EId];
    }
    if (AugFlow < MinAug) { MinAug = AugFlow; }
  }
  return MinAug;
}
开发者ID:Daron-Wan,项目名称:snap,代码行数:34,代码来源:flow.cpp

示例2: GetGroupDegreeCentr0

double GetGroupDegreeCentr0(const PUNGraph& Graph, const TIntH& GroupNodes) {
  int deg;
  TIntH NN;
  for (int i = 0; i<GroupNodes.Len(); i++) {
    deg = Graph->GetNI(GroupNodes.GetDat(i)).GetDeg();
    for (int j = 0; j < deg; j++) {
      if (GroupNodes.IsKey(Graph->GetNI(GroupNodes.GetDat(i)).GetNbrNId(j)) == 0)
        NN.AddDat(Graph->GetNI(GroupNodes.GetDat(i)).GetNbrNId(j), GroupNodes.GetDat(i));
    }
  }
  return (double)NN.Len();
}
开发者ID:Austindeadhead,项目名称:qminer,代码行数:12,代码来源:centr.cpp

示例3: SetLangCntryByMajority

// set Language and Country for movies that do not have the value set
// for every movie find the mojority language/country in 1-hop neighborhood and set it
void TImdbNet::SetLangCntryByMajority() {
  // set language
  while (true) {
    TIntPrV NIdToVal;
    for (TNodeI NI = BegNI(); NI < EndNI(); NI++) {
      if (NI().GetLang() != 0) { continue; }
      int Nbhs=0; TIntH LangCntH;
      for (int e = 0; e < NI.GetOutDeg(); e++) {
        LangCntH.AddDat(NI.GetOutNDat(e).GetLang()) += 1;  Nbhs++; }
      for (int e = 0; e < NI.GetInDeg(); e++) {
        LangCntH.AddDat(NI.GetInNDat(e).GetLang()) += 1;  Nbhs++; }
      if (LangCntH.IsKey(0)) { Nbhs-=LangCntH.GetDat(0); LangCntH.GetDat(0)=0; }
      LangCntH.SortByDat(false);
      if (LangCntH.GetKey(0) == 0) { continue; }
      if (LangCntH[0]*2 >= Nbhs) { 
        NIdToVal.Add(TIntPr(NI.GetId(), LangCntH.GetKey(0))); }
    }
    if (NIdToVal.Empty()) { break; } // done
    for (int i = 0; i < NIdToVal.Len(); i++) {
      GetNDat(NIdToVal[i].Val1).Lang = NIdToVal[i].Val2; }
    printf("  language set: %d\n", NIdToVal.Len());
  }
  int cnt=0;
  for (TNodeI NI = BegNI(); NI < EndNI(); NI++) { if (NI().GetLang()==0) cnt++; }
  printf(" NO language: %d\n\n", cnt);
  // set country
  while (true) {
    TIntPrV NIdToVal;
    for (TNodeI NI = BegNI(); NI < EndNI(); NI++) {
      if (NI().GetCntry() != 0) { continue; }
      int Nbhs=0; TIntH CntryCntH;
      for (int e = 0; e < NI.GetOutDeg(); e++) {
        CntryCntH.AddDat(NI.GetOutNDat(e).GetCntry()) += 1;  Nbhs++; }
      for (int e = 0; e < NI.GetInDeg(); e++) {
        CntryCntH.AddDat(NI.GetInNDat(e).GetCntry()) += 1;  Nbhs++; }
      if (CntryCntH.IsKey(0)) { Nbhs-=CntryCntH.GetDat(0); CntryCntH.GetDat(0)=0; }
      CntryCntH.SortByDat(false);
      if (CntryCntH.GetKey(0) == 0) { continue; }
      if (CntryCntH[0]*2 >= Nbhs) { 
        NIdToVal.Add(TIntPr(NI.GetId(), CntryCntH.GetKey(0))); }
    }
    if (NIdToVal.Empty()) { break; } // done
    for (int i = 0; i < NIdToVal.Len(); i++) {
      GetNDat(NIdToVal[i].Val1).Cntry = NIdToVal[i].Val2; }
    printf("  country set: %d\n", NIdToVal.Len());
  }
  cnt=0;
  for (TNodeI NI = BegNI(); NI < EndNI(); NI++) { if (NI().GetCntry()==0) cnt++; }
  printf(" NO country: %d\n\n", cnt);
}
开发者ID:SherlockYang,项目名称:Archive,代码行数:52,代码来源:imdbnet.cpp

示例4: GetGroupFarnessCentr

double GetGroupFarnessCentr(const PUNGraph& Graph, const TIntH& GroupNodes) {
  TIntH* NDistH = new TIntH[GroupNodes.Len()];

  for (int i = 0; i<GroupNodes.Len(); i++){
    NDistH[i](Graph->GetNodes());
    TSnap::GetShortPath<PUNGraph>(Graph, GroupNodes.GetDat(i), NDistH[i], true, TInt::Mx);
  }

  int min, dist, sum = 0, len = 0;
  for (PUNGraph::TObj::TNodeI NI = Graph->BegNI(); NI < Graph->EndNI(); NI++){
    if (NDistH[0].IsKey(NI.GetId()))
      min = NDistH[0].GetDat(NI.GetId());
    else
      min = -1;
    for (int j = 1; j<GroupNodes.Len(); j++){
      if (NDistH[j].IsKey(NI.GetId()))
        dist = NDistH[j].GetDat(NI.GetId());
      else
        dist = -1;
      if ((dist < min && dist != -1) || (dist > min && min == -1))
        min = dist;
    }
    if (min>0){
      sum += min;
      len++;
    }

  }

  if (len > 0) { return sum / double(len); }
  else { return 0.0; }
}
开发者ID:Austindeadhead,项目名称:qminer,代码行数:32,代码来源:centr.cpp

示例5: FindCascadeRoot

 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;
 }
开发者ID:SherlockYang,项目名称:Archive,代码行数:7,代码来源:cascades.cpp

示例6: MinSup

/////////////////////////////////////////////////
// Trawling the web for emerging communities
// graph, left points to right
TTrawling::TTrawling(const PNGraph& Graph, const int& MinSupport) : MinSup(MinSupport) {
  TIntH ItemCntH;
  for (TNGraph::TNodeI NI = Graph->BegNI(); NI < Graph->EndNI(); NI++) {
    IAssert(NI.GetOutDeg()==0 || NI.GetInDeg()==0); // edges only point from left to right
    if (NI.GetOutDeg()==0) { continue; }
    for (int e = 0; e < NI.GetOutDeg(); e++) {
      ItemCntH.AddDat(NI.GetOutNId(e)) += 1;
    }
  }

  TIntV RightV;
  for (TNGraph::TNodeI NI = Graph->BegNI(); NI < Graph->EndNI(); NI++) {
    IAssert(NI.GetOutDeg()==0 || NI.GetInDeg()==0); // edges only point from left to right
    if (NI.GetOutDeg()==0) { continue; }
    RightV.Clr(false);
    for (int e = 0; e < NI.GetOutDeg(); e++) {
      const int itm = NI.GetOutNId(e);
      // only include items that already are above minimum support
      if (ItemCntH.GetDat(itm) >= MinSup) {
        RightV.Add(itm); }
    }
    if (! RightV.Empty()) {
      NIdSetH.AddDat(NI.GetId(), RightV);
    }
  }
  //
  for (int n = 0; n < NIdSetH.Len(); n++) {
    const TIntV& Set = NIdSetH[n];
    for (int s = 0; s < Set.Len(); s++) {
      SetNIdH.AddDat(Set[s]).Add(n);
    }
  }
}
开发者ID:Aleyasen,项目名称:Alaki,代码行数:36,代码来源:trawling.cpp

示例7: AddSpuriousEdges

// network cascade: add spurious edges
// for more details see "Correcting for Missing Data in Information Cascades" by E. Sadikov, M. Medina, J. Leskovec, H. Garcia-Molina. WSDM, 2011
PNGraph AddSpuriousEdges(const PUNGraph& Graph, const PNGraph& Casc, TIntH NIdTmH) {
  TIntPrV EdgeV;
  for (TNGraph::TNodeI NI = Casc->BegNI(); NI < Casc->EndNI(); NI++) {
    TUNGraph::TNodeI GNI = Graph->GetNI(NI.GetId());
    const int Tm = NIdTmH.GetDat(NI.GetId());
    for (int i=0,j=0; i < GNI.GetOutDeg(); i++) {
      const int Dst = GNI.GetOutNId(i);
      if (NIdTmH.IsKey(Dst) && Tm<NIdTmH.GetDat(Dst) && ! NI.IsNbhNId(Dst)) {
        EdgeV.Add(TIntPr(GNI.GetId(), Dst)); }
    }
  }
  PNGraph NetCasc = TNGraph::New();
  *NetCasc = *Casc;
  for (int e = 0; e < EdgeV.Len(); e++) {
    NetCasc->AddEdge(EdgeV[e].Val1, EdgeV[e].Val2); }
  return NetCasc;
}
开发者ID:SherlockYang,项目名称:Archive,代码行数:19,代码来源:cascades.cpp

示例8: SetActorCntryLangByMajority

// set actor's language and country
void TImdbNet::SetActorCntryLangByMajority() {
    // set language
  TIntPrV NIdToVal;
  for (TNodeI NI = BegNI(); NI < EndNI(); NI++) {
    if (! NI().IsActor()) { continue; }
    IAssert(NI().GetLang() == 0); // no language set
    IAssert(NI.GetInDeg() == 0);  // actors point to movies
    int Nbhs=0;  TIntH LangCntH;
    for (int e = 0; e < NI.GetOutDeg(); e++) {
      LangCntH.AddDat(NI.GetOutNDat(e).GetLang()) += 1;  Nbhs++; }
    if (LangCntH.IsKey(0)) { Nbhs-=LangCntH.GetDat(0); LangCntH.GetDat(0)=0; }
    LangCntH.SortByDat(false);
    if (LangCntH.GetKey(0) == 0) { continue; }
    if (LangCntH[0]*2 >= Nbhs) { 
      NIdToVal.Add(TIntPr(NI.GetId(), LangCntH.GetKey(0))); }
  }
  for (int i = 0; i < NIdToVal.Len(); i++) {
    GetNDat(NIdToVal[i].Val1).Lang = NIdToVal[i].Val2; }
  printf("  language set: %d\n", NIdToVal.Len());
  
  int cnt=0;
  for (TNodeI NI = BegNI(); NI < EndNI(); NI++) { if (NI().IsActor() && NI().GetLang()==0) cnt++; }
  printf("  Actors NO language: %d\n\n", cnt);
  // set country
  NIdToVal.Clr(true);
  for (TNodeI NI = BegNI(); NI < EndNI(); NI++) {
    if (! NI().IsActor()) { continue; }
    IAssert(NI().GetCntry() == 0); // no country set
    IAssert(NI.GetInDeg() == 0);   // actors point to movies
    int Nbhs=0; TIntH CntryCntH;
    for (int e = 0; e < NI.GetOutDeg(); e++) {
      CntryCntH.AddDat(NI.GetOutNDat(e).GetCntry()) += 1;  Nbhs++; }
    if (CntryCntH.IsKey(0)) { Nbhs-=CntryCntH.GetDat(0); CntryCntH.GetDat(0)=0; }
    CntryCntH.SortByDat(false);
    if (CntryCntH.GetKey(0) == 0) { continue; }
    if (CntryCntH[0]*2 >= Nbhs) { 
      NIdToVal.Add(TIntPr(NI.GetId(), CntryCntH.GetKey(0))); }
  }
  for (int i = 0; i < NIdToVal.Len(); i++) {
    GetNDat(NIdToVal[i].Val1).Cntry = NIdToVal[i].Val2; }
  printf("  country set: %d\n", NIdToVal.Len());
  cnt=0;
  for (TNodeI NI = BegNI(); NI < EndNI(); NI++) { if (NI().IsActor() && NI().GetCntry()==0) cnt++; }
  printf("  Actors NO country: %d\n\n", cnt);
}
开发者ID:SherlockYang,项目名称:Archive,代码行数:46,代码来源:imdbnet.cpp

示例9: _GirvanNewmanGetModularity

// Connected components of a graph define clusters
// OutDegH and OrigEdges stores node degrees and number of edges in the original graph
double _GirvanNewmanGetModularity(const PUNGraph& G, const TIntH& OutDegH, const int& OrigEdges, TCnComV& CnComV) {
  TSnap::GetWccs(G, CnComV); // get communities
  double Mod = 0;
  for (int c = 0; c < CnComV.Len(); c++) {
    const TIntV& NIdV = CnComV[c]();
    double EIn=0, EEIn=0;
    for (int i = 0; i < NIdV.Len(); i++) {
      TUNGraph::TNodeI NI = G->GetNI(NIdV[i]);
      EIn += NI.GetOutDeg();
      EEIn += OutDegH.GetDat(NIdV[i]);
    }
    Mod += (EIn-EEIn*EEIn/(2.0*OrigEdges));
  }
  if (Mod == 0) { return 0; }
  else { return Mod/(2.0*OrigEdges); }
}
开发者ID:pikma,项目名称:Snap,代码行数:18,代码来源:cmty.cpp

示例10: GenCascade

void TNetInfBs::GenCascade(TCascade& C, const int& TModel, const double &window, TIntPrIntH& EdgesUsed, const double& delta,
						   const double& std_waiting_time, const double& std_beta) {
	TIntFltH InfectedNIdH; TIntH InfectedBy;
	double GlobalTime; int StartNId;
	double alpha, beta;

	if (GroundTruth->GetNodes() == 0)
		return;

	while (C.Len() < 2) {
		C.Clr();
		InfectedNIdH.Clr();
		InfectedBy.Clr();
		GlobalTime = 0;

		StartNId = GroundTruth->GetRndNId();
		InfectedNIdH.AddDat(StartNId) = GlobalTime;

		while (true) {
			// sort by time & get the oldest node that did not run infection
			InfectedNIdH.SortByDat(true);
			const int& NId = InfectedNIdH.BegI().GetKey();
			GlobalTime = InfectedNIdH.BegI().GetDat();

			// all the nodes has run infection
			if (GlobalTime >= window)
				break;

			// add current oldest node to the network and set its time
			C.Add(NId, GlobalTime);

			// run infection from the current oldest node
			const TNGraph::TNodeI NI = GroundTruth->GetNI(NId);
			for (int e = 0; e < NI.GetOutDeg(); e++) {
				const int DstNId = NI.GetOutNId(e);

				beta = Betas.GetDat(TIntPr(NId, DstNId));

				// flip biased coin (set by beta)
				if (TInt::Rnd.GetUniDev() > beta+std_beta*TFlt::Rnd.GetNrmDev())
					continue;

				alpha = Alphas.GetDat(TIntPr(NId, DstNId));

				// not infecting the parent
				if (InfectedBy.IsKey(NId) && InfectedBy.GetDat(NId).Val == DstNId)
					continue;

				double sigmaT;
				switch (TModel) {
				case 0:
					// exponential with alpha parameter
					sigmaT = TInt::Rnd.GetExpDev(alpha);
					break;
				case 1:
					// power-law with alpha parameter
					sigmaT = TInt::Rnd.GetPowerDev(alpha);
					while (sigmaT < delta) { sigmaT = TInt::Rnd.GetPowerDev(alpha); }
					break;
				case 2:
					// rayleigh with alpha parameter
					sigmaT = TInt::Rnd.GetRayleigh(1/sqrt(alpha));
					break;
				default:
					sigmaT = 1;
					break;
				}

				// avoid negative time diffs in case of noise
				if (std_waiting_time > 0)
					sigmaT = TFlt::GetMx(0.0, sigmaT + std_waiting_time*TFlt::Rnd.GetNrmDev());

				double t1 = GlobalTime + sigmaT;

				if (InfectedNIdH.IsKey(DstNId)) {
					double t2 = InfectedNIdH.GetDat(DstNId);
					if (t2 > t1 && t2 != window) {
						InfectedNIdH.GetDat(DstNId) = t1;
						InfectedBy.GetDat(DstNId) = NId;
					}
				} else {
					InfectedNIdH.AddDat(DstNId) = t1;
					InfectedBy.AddDat(DstNId) = NId;
				}
			}

			// we cannot delete key (otherwise, we cannot sort), so we assign a big time (window cut-off)
			InfectedNIdH.GetDat(NId) = window;
		}

	}

	C.Sort();

	for (TIntH::TIter EI = InfectedBy.BegI(); EI < InfectedBy.EndI(); EI++) {
		TIntPr Edge(EI.GetDat().Val, EI.GetKey().Val);

		if (!EdgesUsed.IsKey(Edge)) EdgesUsed.AddDat(Edge) = 0;

		EdgesUsed.GetDat(Edge) += 1;
//.........这里部分代码省略.........
开发者ID:blizzardwj,项目名称:ML_netinf,代码行数:101,代码来源:cascinf.cpp

示例11: solve

result_t EPFLSolver::solve(const GraphHypothesis& realization,
    vector<pair<double, int>>& clusterSortedScores)
{
  // Get infection times for all the observers and keep ascending.
  vector<pair<double, int>> observers;
  for (int observer : m_observerNodes) {
    // If chosen observers are not infected, we just skip them.
    if (realization.getInfectionTime(observer) == INFECTED_FALSE)
      continue;

    observers.push_back(
        pair<double, int>(realization.getInfectionTime(observer), observer));
  }

  if (observers.size() == 0) {
    result_t empty;

    empty.first = 0;
    empty.second.push_back(0);      // mass
    empty.second.push_back(100);    // diff
    empty.second.push_back(0);      // correct mass

    for (int s = 0; s < m_config.nodes; ++s)
      clusterSortedScores.push_back(pair<double, int>(0.0, s));

    return empty;
  }

  // Everything is related to the reference observer (first infected).
  sort(observers.begin(), observers.end());
  int referenceObserver = observers[0].second;

  // Compute gaussian moments.
  gaussian_t moments;
  if (m_config.infType == BETA) {
    double beta = m_config.cluster.beta;
    moments = make_pair(1.00/beta, sqrt((1.00 - beta)/(beta*beta)));
  } else {
    moments = make_pair(m_config.cluster.miu, m_config.cluster.beta);
  }

  TIntH idToShortestPathsFromReference;
  TSnap::GetShortPath(m_network, referenceObserver, idToShortestPathsFromReference);

  // BFS tree from reference observer. Compute LCA w.r.t. to ref. observer.
  PNGraph bfsTree = TSnap::GetBfsTree<PUNGraph>(
      m_network, referenceObserver, true, true);

  // The method below smartly identifies the lowest common ancestor
  // between two nodes, but wastes quite some memory. Note that because
  // of using unsigned short ints, one shouldn't have nodes with id > 65535

  // TODO(vcarbune): use half of the memory.
  unsigned short int lca[observers.size()][observers.size()];
  for (size_t k = 1; k < observers.size(); ++k) {
    for (size_t i = k + 1; i < observers.size(); ++i) {
      int Ni = observers[i].second;
      int Nk = observers[k].second;
      int heightNi = idToShortestPathsFromReference.GetDat(Ni);
      int heightNk = idToShortestPathsFromReference.GetDat(Nk);

      while (heightNi > heightNk && Ni != referenceObserver) {
        Ni = bfsTree->GetNI(Ni).GetInNId(0);
        heightNi = idToShortestPathsFromReference.GetDat(Ni);
      }
      while (heightNk > heightNi && Nk != referenceObserver) {
        Nk = bfsTree->GetNI(Nk).GetInNId(0);
        heightNk = idToShortestPathsFromReference.GetDat(Nk);
      }
      while (Ni != Nk) {
        Nk = bfsTree->GetNI(Nk).GetInNId(0);
        Ni = bfsTree->GetNI(Ni).GetInNId(0);
      }
      if (heightNk != heightNi || Ni != Nk)
        cout << "Something awfully wrong here" << endl;
      lca[k][i] = lca[i][k] = Ni;
    }
  }

  // Delay Covariance
  Eigen::MatrixXf lambda(observers.size() - 1, observers.size() - 1);
  for (size_t k = 0; k < observers.size() - 1; ++k) {
    for (size_t i = 0; i < observers.size() - 1; ++i) {
      float value = moments.second * moments.second;
      if (k == i)
        value *= idToShortestPathsFromReference.GetDat(observers[k+1].second);
      else
        value *= idToShortestPathsFromReference.GetDat(lca[k+1][i+1]);
      lambda(k, i) = value;
    }
  }

  Eigen::MatrixXf invLambda(observers.size() - 1, observers.size() - 1);
  invLambda = lambda.inverse();

  // Observed Delay
  Eigen::VectorXf d(observers.size() - 1);
  for (size_t o = 0; o < observers.size() - 1; ++o)
    d[o] = observers[o+1].first - observers[0].first;

//.........这里部分代码省略.........
开发者ID:vcarbune,项目名称:netloc,代码行数:101,代码来源:epfl_solver.cpp

示例12: LoadTxt

// load from allactors.zip that was prepared by Brad Malin in 2005
PImdbNet TImdbNet::LoadTxt(const TStr& ActorFNm) {
  PImdbNet Net = TImdbNet::New();
  TStrV ColV;
  char line [2024];
  int NLines=0, DupEdge=0, Year, Position, ActorNId, MovieNId;
  TIntH ActorNIdH;
  THash<TIntPr, TInt> MovieNIdH;
  FILE *F = fopen(ActorFNm.CStr(), "rt");  fgets(line, 2024, F);
  while (! feof(F)) {
    memset(line, 0, 2024);
    fgets(line, 2024, F);
    if (strlen(line) == 0) break;
    TStr(line).SplitOnAllCh('|', ColV, false);  IAssert(ColV.Len() == 7);
    const int NameStrId = Net->AddStr(ColV[0].GetTrunc().GetLc()+" "+ColV[1].GetTrunc().GetLc());
    const int MovieStrId = Net->AddStr(ColV[2].GetTrunc().GetLc());
    TStr YearStr = ColV[3].GetTrunc();
    if (YearStr.Len() > 4) YearStr = YearStr.GetSubStr(0, 3);
    Year = 1;  YearStr.IsInt(Year);
    const TMovieTy MovieTy = TImdbNet::GetMovieTy(ColV[4]);
    Position = TInt::Mx;  ColV[5].GetTrunc().IsInt(Position);
    IAssert(ColV[6].GetTrunc()[0] == 'M' || ColV[6].GetTrunc()[0]=='F');
    const bool IsMale = ColV[6].GetTrunc()[0] == 'M';
    // create nodes  
    if (ActorNIdH.IsKey(NameStrId)) { 
      ActorNId = ActorNIdH.GetDat(NameStrId); }
    else { 
      ActorNId = Net->AddNode(-1, TImdbNode(NameStrId, Year, Position, IsMale));
      ActorNIdH.AddDat(NameStrId, ActorNId);
    }
    if (MovieNIdH.IsKey(TIntPr(MovieStrId, Year))) {
      MovieNId = MovieNIdH.GetDat(TIntPr(MovieStrId, Year)); }
    else {
      MovieNId = Net->AddNode(-1, TImdbNode(NameStrId, Year, MovieTy)); 
      MovieNIdH.AddDat(TIntPr(MovieStrId, Year), MovieNId); 
    }
    if (! Net->IsEdge(ActorNId, MovieNId)) { 
      Net->AddEdge(ActorNId, MovieNId); }
    else { DupEdge++; }
    if (++NLines % 100000 == 0) printf("\r  %dk  ", NLines/1000);
  }
  fclose(F);
  printf("duplicate edges: %d\n", DupEdge);
  printf("nodes:  %d\n", Net->GetNodes());
  printf("edges:  %d\n", Net->GetEdges());
  printf("actors: %d\n", ActorNIdH.Len());
  printf("movies: %d\n", MovieNIdH.Len());
  // set the actor year to the year of his first movie
  int NUpdates=0;
  for (TNet::TNodeI NI = Net->BegNI(); NI < Net->EndNI(); NI++) {
    if (NI().IsActor()) {
      int MinYear = NI().GetYear();
      for (int e = 0; e < NI.GetOutDeg(); e++) {
        const TImdbNode& NodeDat = Net->GetNDat(NI.GetOutNId(e));
        if (NodeDat.IsMovie()) MinYear = TMath::Mn(MinYear, NodeDat.GetYear());
      }
      if (NI().Year != MinYear) NUpdates++;
      NI().Year = MinYear;
    }
  }
  printf("updated actor times: %d\n", NUpdates);
  return Net;
}
开发者ID:SherlockYang,项目名称:Archive,代码行数:63,代码来源:imdbnet.cpp

示例13: PaintCatNms

void TVizMapContext::PaintCatNms(PGks Gks, const int& KeyWdFontSize, 
        TVec<TFltRect>& PointNmRectV) {
        
    // calculate frequency of categories
    TIntH CatH; TIntFltPrH CatPosH;
    PBowDocBs BowDocBs = VizMapFrame->GetKeyWdBow();
    const int Points = VizMapFrame->GetPoints();
    for (int PointN = 0; PointN < Points; PointN++) {
        PVizMapPoint Point = VizMapFrame->GetPoint(PointN);
        const int DId = Point->GetDocId();
        const int CIds = BowDocBs->GetDocCIds(DId);
        for (int CIdN = 0; CIdN < CIds; CIdN++) {
            const int CId = BowDocBs->GetDocCId(DId, CIdN);
            CatH.AddDat(CId)++;
            CatPosH.AddDat(CId).Val1 += Point->GetPointX();
            CatPosH.AddDat(CId).Val2 += Point->GetPointY();
        }
        
    }
    CatH.SortByDat(false); 

    // draw the top cats
    const int TopCats = Points > 100 ? 6 : 4; 
    TFltRect ZoomRect = GetZoomRect();    
    Gks->SetFont(TGksFont::New("ARIAL", KeyWdFontSize + 3, ColorCatNmFont));
    TVec<TFltRect> CatNmRectV; TVec<TFltV> CatNmPosV;
    const int MnSize = TInt::GetMn(Gks->GetWidth(), Gks->GetHeight());
    const int MnDist = TFlt::Round(0.3 * double(MnSize));
    int Cats = 0, CatKeyId = CatH.FFirstKeyId();
    while (CatH.FNextKeyId(CatKeyId)) {
        if (Cats == TopCats) { break; } 
        if (double(CatH[CatKeyId]) / double(Points) < 0.05) { break; } 
        const int CId = CatH.GetKey(CatKeyId);
        // get name
        TStr CatNm = BowDocBs->GetCatNm(CId);
        if (CatFullNmH.IsKey(CatNm)) {
            CatNm = CatFullNmH.GetDat(CatNm);
        } else { continue; }
        // get position
        TFltPr CatPos = CatPosH.GetDat(CId);
        const int CatCount = CatH.GetDat(CId); IAssert(CatCount > 0);
        const double CatX = CatPos.Val1 / double(CatCount);
        const double CatY = CatPos.Val2 / double(CatCount);
        // is it within the zoom?
        if (!ZoomRect.IsXYIn(CatX, CatY)) { continue; }
        // calculate string size on the screen
        const int HalfTxtWidth = Gks->GetTxtWidth(CatNm) / 2;
        const int HalfTxtHeight = Gks->GetTxtHeight(CatNm) / 2;
        // get coordinates in pixels
        const int X = GetScreenCoord(CatX , ZoomRect.GetMnX(), 
            ZoomRect.GetXLen(), Gks->GetWidth());
        const int Y = GetScreenCoord(CatY, ZoomRect.GetMnY(), 
            ZoomRect.GetYLen(), Gks->GetHeight());
        // is it to close to any of the most prominent categories
        int CatNmDist = MnSize; TFltV CatNmPos = TFltV::GetV(double(X), double(Y));
        for (int CatNmPosN = 0; CatNmPosN < CatNmPosV.Len(); CatNmPosN++) {
            const double Dist = TLinAlg::EuclDist(CatNmPosV[CatNmPosN], CatNmPos);
            CatNmDist = TInt::GetMn(TFlt::Round(Dist), CatNmDist);
        }
        if (CatNmDist < MnDist) { continue; }
        // does it overlap with any of hte most prominent categories
        TFltRect CatNmRect(X - HalfTxtWidth, Y - HalfTxtHeight,
            X + HalfTxtWidth, Y + HalfTxtHeight);
        bool DoDraw = true; const int Rects = CatNmRectV.Len();
        for (int RectN = 0; (RectN < Rects) && DoDraw; RectN++) {
            DoDraw = !TFltRect::Intersection(CatNmRect, CatNmRectV[RectN]); }
        if (!DoDraw) { continue; }
        // draw it!
        Gks->PutTxt(CatNm, X - HalfTxtWidth, Y - HalfTxtHeight); 
        // remember string area
        CatNmRectV.Add(CatNmRect); Cats++;
        // remember string position
        CatNmPosV.Add(CatNmPos);
    }
    PointNmRectV.AddV(CatNmRectV);
}
开发者ID:mkarlovc,项目名称:gcentralization,代码行数:76,代码来源:vizmapgks.cpp


注:本文中的TIntH::GetDat方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。