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


C++ Graph::EndNI方法代码示例

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


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

示例1: kruskalCluster

void kruskalCluster(Graph & G)
{
    std::vector<Cluster> clusters;
    for (SnapNode NI = G->BegNI(); NI < G->EndNI(); NI++)
    {
        Cluster c;
        c.empty = false;
        c.clusterElements.push_back(NI.GetDat());
        clusters.push_back(c);
    }

    std::vector <SnapEdge> result;
    std::deque <SnapEdge> Q;

    for (SnapEdge NI = G->BegEI(); NI < G->EndEI(); NI++)
    {
        Q.push_back(NI);
    }

    while(!Q.empty())
    {
        std::sort(Q.begin(), Q.end(), sortClusters);
        SnapEdge edge = Q.front();
        Q.pop_front();
        if(!compareCluster((int)edge.GetSrcNDat(), (int)edge.GetDstNDat(), clusters))
        {
            result.push_back(edge);
        }
    }

    for(int i = 0; i<result.size(); i++)
    {
        std::cout << "(" << result[i].GetSrcNDat() << ", " << result[i].GetDstNDat() << ", " << result[i].GetDat() << ")" << std::endl;
    }
}
开发者ID:sexistaMatula,项目名称:SNAP-Graph,代码行数:35,代码来源:testgraph.cpp

示例2: getLargestNode

int getLargestNode(Graph & G)
{
    int largest = G->BegNI().GetDat();
    for (SnapNode NI = G->BegNI(); NI != G->EndNI(); NI++)
    {
        if(NI.GetDat() > largest)
            largest = NI.GetDat();
    }
    return largest;
}
开发者ID:sexistaMatula,项目名称:SNAP-Graph,代码行数:10,代码来源:testgraph.cpp

示例3: printDetail

void printDetail(Graph & G)
{
    for (SnapNode NI = G->BegNI(); NI != G->EndNI(); NI++)
    {
        std::cout << "Id: " << NI.GetId() << " Out Degree: " << NI.GetOutDeg() << " In Degree: " << NI.GetInDeg() << std::endl;
    }

    for (SnapEdge NI = G->BegEI(); NI < G->EndEI(); NI++)
    {
        std::cout << "Edge from " << (int)NI.GetSrcNDat() << " --> " << (int)NI.GetDstNDat() << " with weight " << (int)NI.GetDstNDat() << std::endl;
    }
}
开发者ID:sexistaMatula,项目名称:SNAP-Graph,代码行数:12,代码来源:testgraph.cpp

示例4: dijkstra

void dijkstra(Graph & G, int v, bool bench)
{
    int size = G->GetNodes();
    std::vector<float> distances (size,inf);
    std::vector<int> parents (size,-1);
    std::priority_queue<std::pair<float, Graph::TObj::TNodeI> > queue;

    distances[v-1] = 0;
	parents[v-1] = -1;

    for(SnapNode NI = G->BegNI(); NI != G->EndNI(); NI++)
    {
		queue.push(std::make_pair(distances[NI.GetDat()-1], NI));
    }

    while(!queue.empty())
    {
        SnapNode u = queue.top().second;
        float dist = queue.top().first;
        queue.pop();

        int sourceNode = u.GetDat();
        for (int ed = 0; ed < u.GetOutDeg(); ed++)//For each adjacent vertex to node NI
        {
            int destNode = u.GetOutNDat(ed);
            SnapEdge e =  G->GetEI(sourceNode,destNode);
			float alt = dist + e.GetDat();
            if(alt < distances[destNode-1])//relax
            {
                distances[destNode-1] = alt;
                parents[destNode-1] = sourceNode;
                queue.push(std::make_pair(alt, G->GetNI(destNode)));
            }
        }
    }
    if(!bench)
    {
        int node = 1;
        for (int i = 0 ; i< parents.size(); i++)
        {
            if(parents[node-1] == -1)
                std::cout << "start -> " << node << " distance:  " << distances[node-1] << std::endl;
            else
                std::cout << parents[node-1] << " -> " << node << " distance:  " << distances[node-1] << std::endl;
            node++;
        }
    }
}
开发者ID:sexistaMatula,项目名称:SNAP-Graph,代码行数:48,代码来源:testgraph.cpp

示例5: kruskal

void kruskal(Graph & G, bool bench)
{
    int largestNode = getLargestNode(G);
    std::vector<disjointTreeNode*> disjointNodes(largestNode);
    std::vector<SnapEdge> result;
    std::deque<SnapEdge> Q;

    for(SnapNode NI = G->BegNI(); NI < G->EndNI(); NI++)
    {
        disjointTreeNode* x =  new disjointTreeNode();
        x->id = NI.GetDat();
        makeSet(x);
        disjointNodes[x->id-1] = x;
    }


    for (SnapEdge NI = G->BegEI(); NI < G->EndEI(); NI++)
    {
        Q.push_back(NI);
    }

    while (! Q.empty())
    {
        std::sort(Q.begin(), Q.end(), sortClusters);
        SnapEdge e = Q.front();
        Q.pop_front();
        disjointTreeNode* u = Find(disjointNodes[e.GetSrcNDat()-1]);
        disjointTreeNode* v = Find(disjointNodes[e.GetDstNDat()()-1]);
        if ( u != v )
        {
            result.push_back(e);
            Union(disjointNodes[e.GetSrcNDat()-1], disjointNodes[e.GetDstNDat()-1]);
        }

    }
    if(!bench)
    {
        for(int i = 0; i<result.size(); i++)
        {
            std::cout << result[i].GetSrcNDat() << " --> " << result[i].GetDstNDat() << " peso: " << result[i].GetDat() << std::endl;
        }
    }
}
开发者ID:sexistaMatula,项目名称:SNAP-Graph,代码行数:43,代码来源:testgraph.cpp


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