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


C++ TPt::GetMxNId方法代码示例

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


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

示例1: GraphUnion

//???????
TPt<TNodeEDatNet<TFlt, TFlt>> GenerateDAG2(const TPt<TNodeEDatNet<TFlt, TFlt>>& pGraph, const std::vector<int> &vSeedIDs, double dThreshold)
{
	// Vector of MIOA graphs per seed node
	std::vector<TPt<TNodeEDatNet<TFlt, TFlt>>> vMIOAGraphs;

	// Compute the union of MIOA for each node of vSeedIDs
	for(auto it=vSeedIDs.begin(); it!=vSeedIDs.end(); ++it)
		vMIOAGraphs.push_back(MIOA(pGraph, *it, dThreshold));
	auto pOut = GraphUnion(vMIOAGraphs);

	// Set node data
	for (auto NI = pOut->BegNI(); NI < pOut->EndNI(); NI++)
		pOut->SetNDat(NI.GetId(), FLT_MAX);

	// Copy the edge weights from pGraph
	for (auto EI = pOut->BegEI(); EI < pOut->EndEI(); EI++)
		pOut->SetEDat(EI.GetSrcNId(), EI.GetDstNId(), pGraph->GetEDat(EI.GetSrcNId(), EI.GetDstNId()));

	// Create a super root in order to update in one pass all the shortest paths from vSeedIDs nodes
	int superRootID = pGraph->GetMxNId()+1;
	pOut->AddNode(superRootID);
	for(auto it=vSeedIDs.begin(); it!=vSeedIDs.end(); ++it)
	{
		pOut->AddEdge(superRootID, *it);
		pOut->SetEDat(superRootID, *it, 1.0);
	}
	Dijkstra(pOut, superRootID, dThreshold, pOut);
	// Remove the artificial super root node
	pOut->DelNode(superRootID);

	// Traverse the edges and prune the graph
	for (auto EI = pOut->BegEI(); EI < pOut->EndEI(); EI++)
	{
		if(EI.GetDstNDat().Val < EI.GetSrcNDat().Val)
			pOut->DelEdge(EI.GetSrcNId(), EI.GetDstNId());
	}

	//Reset Node data from the original graph
	for (auto NI = pGraph->BegNI(); NI < pGraph->EndNI(); NI++)
		pOut->SetNDat(NI.GetId(),NI.GetDat().Val);

	return pOut;
}
开发者ID:guorongYu,项目名称:Belief-Propagation,代码行数:44,代码来源:Utilities.cpp

示例2: MaxIncrementalInfluence

std::vector<int> MaxIncrementalInfluence(TPt<TNodeEDatNet<TFlt, TFlt>>& pGraph, int numRounds){

	std::vector<int> vSeedSet;
	tbb::concurrent_unordered_map<int,double> mSpreadIncrement;
	auto pGraph_temp = TNodeEDatNet<TFlt, TFlt>::New();
	double influence = 0.0; int i,chunk = 50;
	static tbb::spin_mutex sMutex;

	//Failure of using PeerSeeds due to insufficient memory
	//std::map<int,std::vector<int> > mPeerSeeds;
	//std::map<int,TPt<TNodeEDatNet<TFlt, TFlt>> > mMIOAs;

	/* Initialization*/
	int numNodes = pGraph->GetMxNId();
	#pragma omp parallel shared(pGraph,chunk,mSpreadIncrement) private(pGraph_temp,i)
	{
		#pragma omp for schedule(dynamic,chunk) nowait
			for (i =0;i<numNodes;++i)
			{
				if(pGraph->IsNode(i))
				{
					pGraph_temp = MIOA(pGraph, i, 0);
					InitializationBeforePropagation(pGraph_temp);
					ParallelBPFromNode_1DPartitioning(pGraph_temp, i);
					mSpreadIncrement[i]=InfluenceSpreadFromSeedNodes(pGraph_temp);
					//mMIOAs.insert(std::make_pair(i,pGraph_v));
				}

			}
	}

/*
	//build PeerSeeds
	//Failure due to the insufficient memory
	for (int v =0; v<pGraph->GetNodes();++v)
		if(pGraph->IsNode(v))
			mPeerSeeds[v]=GetPeerSeeds(mMIOAs,v);
*/

	cout<<"--------------------------Finished Initialization---------------------"<<endl;

	for (int i=0;i<numRounds;++i)
	{
		/* select the i'th seed by finding u = argmax(mSpreadIncrement)*/
		auto it = std::max_element(mSpreadIncrement.begin(),mSpreadIncrement.end(),
							[&](std::pair<int,double> const& a, std::pair<int,double> const& b) {
								 return a.second < b.second;
								 }
							);
		int SeedID = it->first;
		cout << SeedID <<endl;

		/* calculate the current influence spread */
		vSeedSet.push_back(SeedID);
		pGraph = GenerateDAG1(pGraph, vSeedSet, 0.0);
		ParallelBPFromNode_1DPartitioning(pGraph, vSeedSet);
		influence = InfluenceSpreadFromSeedNodes(pGraph);

		/*remove the newly selected node*/
		mSpreadIncrement.unsafe_erase(SeedID);

		/* update incremental influence spread for each round */
		double Delta_MAX = 0.0;
		std::vector<int> vSeedSet_temp = vSeedSet;
		#pragma omp parallel shared(pGraph,chunk,vSeedSet,mSpreadIncrement,Delta_MAX) private(pGraph_temp,vSeedSet_temp,i)
		{
			#pragma omp for schedule(dynamic,chunk) nowait
				for (i =0;i<numNodes;++i)
				{
					/* exclude the nodes in seed set */
					auto result = std::find(vSeedSet.begin(),vSeedSet.end(), i);
					if (result != vSeedSet.end()) continue;

					if(pGraph->IsNode(i) && mSpreadIncrement[i] > Delta_MAX)
					{
						/*different processors use different copied vSeedSet*/
						vSeedSet_temp.push_back(i);

						pGraph_temp = GenerateDAG1(pGraph, vSeedSet_temp, 0);
						ParallelBPFromNode_1DPartitioning(pGraph_temp, vSeedSet_temp);
						mSpreadIncrement[i]=InfluenceSpreadFromSeedNodes(pGraph_temp)-influence;
						if (mSpreadIncrement[i]> Delta_MAX)
						{
							tbb::spin_mutex::scoped_lock lock(sMutex);
							Delta_MAX = mSpreadIncrement[i];
						}
						vSeedSet_temp.pop_back();
					}
				}
		}
	}
	return vSeedSet;
}
开发者ID:guorongYu,项目名称:Belief-Propagation,代码行数:93,代码来源:Utilities.cpp


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