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


C++ GraphComponent::getRequiredRam方法代码示例

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


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

示例1: assignPath

void InternalGraph::assignPath(AntPath * pt)
{
    GraphComponent * gc;
    const std::vector<PathElement *> & path = pt->getPath();
    for (int i = 0; i < path.size(); ++ i)
    {
        if (path[i]->request == 0) continue;
        gc = vertices[path[i]->request-1];
        if (gc->getType() == GraphComponent::VMACHINE)
        {
            curNodesRes[path[i]->resource] -= gc->getRequired();
            curNodesRam[path[i]->resource] -= gc->getRequiredRam();
        }
        else if (gc->getType() == GraphComponent::STORAGE) curStoresRes[path[i]->resource] -= gc->getRequired();
    }
}
开发者ID:MargaritaShakhova,项目名称:DataCenters,代码行数:16,代码来源:internalgraph.cpp

示例2: 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;
}
开发者ID:MargaritaShakhova,项目名称:DataCenters,代码行数:70,代码来源:internalgraph.cpp


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