コード例 #1
0
ファイル: networkconstraints.cpp プロジェクト: actnet/saedb
int NetworkConstraints::getNetworkConstraints(string resFile)
{
	try
    {
        sae::io::MappedGraph* g = sae::io::MappedGraph::Open(graphFile.c_str());
        for (auto e = g->Edges(); e->Alive(); e->Next()) 
        {
            EData ed = sae::serialization::convert_from_string<EData>(e->Data());
            ed.value = 0;
            for(auto es = e->Source()->OutEdges(); es->Alive(); es->Next())
            {
                for(auto ee = es->Target()->OutEdges(); ee->Alive(); ee->Next())
                {
                    if (ee->Target()->GlobalId() == e->Target()->GlobalId())
                    {
                        ed.value += sae::serialization::convert_from_string<EData>(es->Data()).attribute[0] * 
                        sae::serialization::convert_from_string<EData>(ee->Data()).attribute[0];
                        break;
                    }
                }
            }
            e->Data() = sae::serialization::convert_to_string<EData>(ed);     
        }
        ofstream outfile(resFile);
        for (auto v = g->Vertices(); v->Alive(); v->Next()) 
        {
            double value = 0;
            VData vd = sae::serialization::convert_from_string<VData>(v->Data());
            for(auto e = v->OutEdges(); e->Alive(); e->Next())
            {
                value += sae::serialization::convert_from_string<EData>(e->Data()).value;
            }
            if(v->OutEdgeCount() > 0)
            {
                outfile << vd.name << "\t" << value / v->OutEdgeCount() <<"\n";
            }
            else
            {
                outfile << vd.name << "\t" << 0 <<"\n";
            }
        }
        cout<<"compute Network Constraints done."<<endl;
    }
    catch(...)
    {
        cout << "Network Constraints parameter error" << endl;
        return -1;
    }
    return 0;
}
コード例 #2
0
ファイル: graph.hpp プロジェクト: mabodx/saedb
 size_t num_out_edges(const vertex_id_type vid) const {
     auto ei = graph->Vertices();
     ei->MoveTo(vid);
     return ei->OutEdges()->Count();
 }
コード例 #3
0
ファイル: averagesssp.cpp プロジェクト: actnet/saedb
int AverageSSSP::getAverageSSSP()
{
	try
    {
        double** dist;
        double MAX = 10000000;
        int paircount = 0;
        double distance = 0;
        sae::io::MappedGraph* g = sae::io::MappedGraph::Open(graphFile.c_str());
        dist = new double*[g->VertexCount()];
        for(int i = 0; i < g->VertexCount(); i++)
        {
            dist[i] = new double[g -> VertexCount()];
            for(int j = 0; j < g->VertexCount(); j++)
            {
                dist[i][j] = MAX;
            }            
        }
        for (auto v = g->Vertices(); v->Alive(); v->Next()) 
        {
            for(auto e = v->OutEdges(); e->Alive(); e->Next())
            {
                dist[v->GlobalId()][e->Source()->GlobalId()] = sae::serialization::convert_from_string<EData>(e->Data()).attribute[0];                
            }
        }
        int maxIter = g->VertexCount() / 1000;
        int lastIter = -10;
        for(int k = 0; k < g->VertexCount() / 1000; k++)
        {
            if (k * 100 / maxIter >= lastIter + 10)
            {
                lastIter = k * 100 / maxIter;
                printf("Processing %d%%...\n", lastIter);
            }
            for(int i = 0; i < g->VertexCount(); i++)
            {
                for(int j = 0; j < g->VertexCount(); j++)
                {
                    if(dist[i][j] > dist[i][k] + dist[k][j])
                    {
                        dist[i][j] = dist[i][k] + dist[k][j];
                    }
                }
            }
        }
        for(int i = 0; i < g->VertexCount(); i++)
        {
            for(int j = 0; j < g->VertexCount(); j++)
            {
                if(dist[i][j] < MAX)
                {
                    paircount ++;
                    distance += dist[i][j];
                }
            }
        }
        if(paircount > 0)
        {            
            cout<<"Average SSSP: " << distance / paircount << endl;
        }
        else
        {
            cout<<"Average SSSP: " << 0 << endl;
        }
    }
    catch(...)
    {
        cout<<"AverageSSSP parameter error"<<endl;
        return -1;
    }
    return 0;
}