Beispiel #1
0
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;
    }
}
Beispiel #2
0
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;
    }
}
Beispiel #3
0
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;
        }
    }
}
Beispiel #4
0
void floydWarshallPaths(Graph & G, int size, bool bench)
{
    std::vector< std::vector<float > > VectorGraph(size, std::vector<float>(size, inf));
    for(int i=0; i<VectorGraph.size(); i++)
    {
        for(int j = 0; j<VectorGraph.size(); j++)
        {
            if(i == j)
                VectorGraph[i][j] = 0;
        }
    }
    for (TNodeEDatNet<TInt, TFlt>::TEdgeI NI = G->BegEI(); NI < G->EndEI(); NI++)
    {
        int vert1 = NI.GetSrcNDat();
        int vert2 = NI.GetDstNDat();
        VectorGraph[vert1-1][vert2-1] = (float) NI.GetDat();
    }
    floydWarshall(VectorGraph);
    if(!bench)
        printFloydWarshall(VectorGraph);
}