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


C++ ListDigraph::valid方法代码示例

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


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

示例1: main


//.........这里部分代码省略.........
    
    // ------------------------------
    // --- Temporal Edges
    // ------------------------------
    vector<int> times;
    boost::unordered_map< int,  vector<ListDigraph::Arc > >   mTimeToArcs;
    times = tempGR::readTemporalArcList(mGraph, mTimeToArcs, sourceTempEdge);
    
    // ------------------------------
    // --- Determine the components
    // ------------------------------
    cout << "- CALCULATION\n";
    ListDigraph::NodeMap<int>      mCompIds(mGraph);
    mapFill(mGraph, mCompIds, -1);
    int nrComponents        = connectedComponents( undirector( mGraph ), mCompIds );
    
    // Determine the ID with the biggest component
    vector<int>     mIDcount(nrComponents,0);
    for (ListDigraph::NodeIt n(mGraph); n!=INVALID; ++n) {
        mIDcount[ mCompIds[ n ] ]++;
    }
    auto a = max_element( mIDcount.begin(), mIDcount.end() );
    int maxCompID = distance( mIDcount.begin(), a );

    cout << "Nodes: " << countNodes( mGraph ) << " components: " << countConnectedComponents( undirector( mGraph ) ) << endl;
    cout << "Max Comp ID: " << maxCompID << " size: " << *a << endl;
//    int i = 0;
//    for ( auto x : mIDcount ){
//    cout << "Comp ID: " << i++ << " size: " << x << endl;
//    }
    
    // ------------------------------
    // --- Mark nodes of the biggest component
    // ------------------------------
    cout << "- PROCESSING\n";
    vector< ListDigraph::Node >    eraseNodes;
    for (ListDigraph::NodeIt n(mGraph); n!=INVALID; ++n) {
        if ( mCompIds[ n ] != maxCompID) {
            eraseNodes.push_back(n);
        }
    }
    
    cout << "The complete graph has " << countConnectedComponents( undirector( mGraph ) )
    << " components and " << countNodes(mGraph) << " nodes" <<  endl;
    
    
    // ------------------------------
    // --- erase the nodes
    // ------------------------------
    for (auto n : eraseNodes){
        mGraph.erase( n );
    }
    
    cout << "The new graph has " << countConnectedComponents( undirector( mGraph ) )
    << " components and " << countNodes(mGraph) << " nodes" << endl;
    
    ListDigraph     newGraph;
    ListDigraph::ArcMap< ListDigraph::Arc >     arcRef( mGraph);
    ListDigraph::NodeMap< ListDigraph::Node>    nodeRef( mGraph );
    
    digraphCopy( mGraph, newGraph)
    .arcRef(arcRef)  // arcMap[ oldArc ] = newArc
    .nodeRef(nodeRef)
    .run();
    
    // ------------------------------
    // --- erase the invalid temporal edges
    // ------------------------------
    vector< vector< ListDigraph::Arc > >    newTempArcs;
    for (auto i : times){
        vector<ListDigraph::Arc>  validArcs;
        for (auto arc : mTimeToArcs[i]){
            if ( mGraph.valid( arc ) )
                validArcs.push_back( arcRef[ arc ] );
        }
        newTempArcs.push_back( validArcs ); // assign new arc set
    }
    
    // ------------------------------
    // --- save the static graph
    // ------------------------------
    cout << "- WRITING\n";
    string  pathLFG = target;
    pathLFG += "_LargesComponent.lfg";
    
    digraphWriter( mGraph, pathLFG)
//    .nodeMap("oldNodes", nodeRef)
//    .arcMap("oldArcs", arcRef)
    .run();
    
    // ------------------------------
    // --- save the temporal arcs
    // ------------------------------
    string  pathTempArc = target;
    pathTempArc += "_LargesComponent_tempArcs.txt";
    
    tempGR::writeTempGraph<ListDigraph>( mGraph, newTempArcs, pathTempArc);
    
    cout << "- DONE\n";
}
开发者ID:BildPeter,项目名称:DynamicNetSim,代码行数:101,代码来源:Process_BiggestComponent.cpp


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