本文整理汇总了C++中GraphComponent::getPointer方法的典型用法代码示例。如果您正苦于以下问题:C++ GraphComponent::getPointer方法的具体用法?C++ GraphComponent::getPointer怎么用?C++ GraphComponent::getPointer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GraphComponent
的用法示例。
在下文中一共展示了GraphComponent::getPointer方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: selectVertex
unsigned int InternalGraph::selectVertex(AntPath* pt, unsigned int cur, std::set<unsigned int> & available, bool& s, std::map<Element *, std::set<Link *> >& chan)
{
// choose request
unsigned int vertex = 0;
unsigned int size = available.size();
std::vector<double> roulette(size);
std::vector<unsigned int> rouletteIndex(size);
double value = 0, sum = 0;
unsigned int index = 0;
std::set<unsigned int>::iterator itEnd = available.end();
for (std::set<unsigned int>::iterator i = available.begin(); i != itEnd; i ++, index ++)
{
value = pow(arcs[cur][*i]->pher, pherDeg)*pow(arcs[cur][*i]->heur, heurDeg);
sum += value;
roulette[index] = sum;
rouletteIndex[index] = *i;
}
double choose = rand()/(double)RAND_MAX * sum;
if (ZERO(sum))
{
std::set<unsigned int>::iterator sel = available.begin();
vertex = *sel;
available.erase(sel);
}
else
{
for (unsigned int i = 0; i < size; ++ i)
{
if (choose < roulette[i])
{
vertex = rouletteIndex[i];
unsigned int res = available.erase(rouletteIndex[i]);
assert(res == 1);
break;
}
}
}
// choose resource
GraphComponent * gc = vertices[vertex-1];
unsigned int res = gc->chooseResource(curNodesRam, pherDeg, heurDeg);
if (res >= gc->getResNum())
{
// failed to choose a resource
s = false;
return vertex;
}
if (gc->getType() == GraphComponent::VMACHINE)
{
curNodesRes[res] -= gc->getRequired();
curNodesRam[res] -= gc->getRequiredRam();
updateInternalHeuristic(res, GraphComponent::VMACHINE);
std::map<Element *, std::set<Link *> >::iterator iter = chan.find(gc->getPointer());
std::set<Link *> * chanPtr = (iter != chan.end()) ? &(iter->second) : NULL;
pt->addElement(new PathElement(vertex, gc->getPointer(), res, physNodes[res], chanPtr));
}
else if (gc->getType() == GraphComponent::STORAGE)
{
curStoresRes[res] -= gc->getRequired();
updateInternalHeuristic(res, GraphComponent::STORAGE);
std::map<Element *, std::set<Link *> >::iterator iter = chan.find(gc->getPointer());
std::set<Link *> * chanPtr = (iter != chan.end()) ? &(iter->second) : NULL;
pt->addElement(new PathElement(vertex, gc->getPointer(), res, physStores[res], chanPtr));
}
s = true;
return vertex;
}