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


C++ GraphNode::getCPUID方法代码示例

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


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

示例1: DFS

void AffinityTask::DFS(std::list<std::list<GraphNode>>& saveAt, const std::unordered_map<CPUID, TaskSet>& cpuToTaskList,
			const std::unordered_map<AffinityTask*, Affinity>& taskToCPUList,
			const GraphNode& start, const GraphNode& target, const std::list<GraphNode>& visited)
{
	std::list<GraphNode> currentVisited(visited);
	currentVisited.push_back(start);
	if(start.isTask() == target.isTask())
	{
		if(start.isTask())
			if(target.getTask() == start.getTask())
			{
				saveAt.push_back(currentVisited);
				return;
			}
		if(!start.isTask())
			if(target.getCPUID() == start.getCPUID())
			{
				saveAt.push_back(currentVisited);
				return;
			}
	}

	if(start.isTask())
	{
		auto iter = taskToCPUList.find(start.getTask());
		if(iter == taskToCPUList.end())
			return;
		for(CPUID adjacentCPU : iter->second) //u ← G.adjacentVertex(t,e)
		{
			bool ifVisited = false;
			for(auto item : visited)
			{
				if(!item.isTask())
				{
					if(item.getCPUID() == adjacentCPU)
					{
						ifVisited = true;
						break;
					}
				}
			}
			if(ifVisited)
				continue;
			DFS(saveAt, cpuToTaskList, taskToCPUList,
					adjacentCPU, target, currentVisited);
		}
	}
	else
	{
		auto iter = cpuToTaskList.find(start.getCPUID());
		if(iter == cpuToTaskList.end())
			return;
		for(AffinityTask* adjacentTask : iter->second) //u ← G.adjacentVertex(t,e)
		{
			bool ifVisited = false;
			for(auto item : visited)
			{
				if(item.isTask())
				{
					if(item.getTask() == adjacentTask)
					{
						ifVisited = true;
						break;
					}
				}
			}
			if(ifVisited)
				continue;
			DFS(saveAt, cpuToTaskList, taskToCPUList,
					adjacentTask, target, currentVisited);
		}
	}
}
开发者ID:HyeongiKim,项目名称:Introduction_to_Network_KENSv3,代码行数:73,代码来源:E_Affinity.cpp

示例2: affinityCopy

std::list<GraphNode> AffinityTask::BFS(const TaskSet& taskSet, const GraphNode& start, const GraphNode& target, const Affinity& excludeID, const TaskSet& excludeTask)
{
	std::list<GraphNode> returnList;

	//prepare link map
	std::unordered_map<CPUID, TaskSet> cpuToTaskList;
	std::unordered_map<AffinityTask*, Affinity> taskToCPUList;
	for(auto task : taskSet)
	{
		if(excludeTask.find(task) != excludeTask.end())
			continue;
		Affinity affinityCopy(task->affinity);
		for(auto cpu : excludeID)
			affinityCopy.erase(cpu);
		taskToCPUList.insert(std::pair<AffinityTask*, Affinity>(task, affinityCopy));
		for(CPUID cpu : affinityCopy)
		{
			if(cpuToTaskList.find(cpu) == cpuToTaskList.end())
				cpuToTaskList.insert(std::pair<CPUID, TaskSet>(cpu, TaskSet()));

			cpuToTaskList.find(cpu)->second.insert(task);
		}
	}

	//procedure BFS(G,v) is
	std::unordered_map<CPUID, AffinityTask*> cpuToPrevTask;
	std::unordered_map<AffinityTask*, CPUID> taskToPrevCPU;
	bool reachable = false;

	std::queue<GraphNode> queue;//create a queue Q, true is Job, false is processor
	std::unordered_set<CPUID> visitedCPU; //create a set V
	std::unordered_set<AffinityTask*> visitedTask; //create a set V

	if(start.isTask())
		visitedTask.insert(start.getTask()); //add v to V
	else
		visitedCPU.insert(start.getCPUID());
	queue.push(start); //enqueue v onto Q

	while(!queue.empty())//while Q is not empty loop
	{
		auto currentItem = queue.front(); //t ← Q.dequeue()
		queue.pop();

		if(currentItem.isTask())
		{
			if(target.isTask())
				if(target.getTask() == currentItem.getTask()) //if t is what we are looking for then
				{
					//return t
					reachable = true;
					break;
				}
		}
		else
		{
			if(!target.isTask())
				if(target.getCPUID() == currentItem.getCPUID()) //if t is what we are looking for then
				{
					//return t
					reachable = true;
					break;
				}
		}

		//for all edges e in G.adjacentEdges(t) loop
		if(currentItem.isTask())
		{
			AffinityTask* curTask = currentItem.getTask();
			assert(curTask != nullptr);

			for(CPUID adjacentCPU : taskToCPUList.find(curTask)->second) //u ← G.adjacentVertex(t,e)
			{
				if(visitedCPU.find(adjacentCPU) == visitedCPU.end()) //if u is not in V then
				{
					visitedCPU.insert(adjacentCPU); //add u to V
					queue.push(GraphNode(adjacentCPU)); //enqueue u onto Q

					assert(cpuToPrevTask.find(adjacentCPU) == cpuToPrevTask.end());
					cpuToPrevTask.insert(std::pair<CPUID,AffinityTask*>(adjacentCPU, curTask));
				}
			}
		}
		else
		{
			CPUID curCPU = currentItem.getCPUID();
			auto iter = cpuToTaskList.find(curCPU);
			if(iter == cpuToTaskList.end())
			{
				continue;
			}
			assert(iter->second.size() > 0);
			for(AffinityTask* adjacentTask : iter->second) //u ← G.adjacentVertex(t,e)
			{
				if(visitedTask.find(adjacentTask) == visitedTask.end())
				{
					visitedTask.insert(adjacentTask);
					queue.push(GraphNode(adjacentTask));

					assert(taskToPrevCPU.find(adjacentTask) == taskToPrevCPU.end());
//.........这里部分代码省略.........
开发者ID:HyeongiKim,项目名称:Introduction_to_Network_KENSv3,代码行数:101,代码来源:E_Affinity.cpp


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