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


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

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


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

示例1: main

int main(int argc, char** argv){
    
    // ------------------------------
    // --- INPUT - OUTPUT
    // ------------------------------
    string  sourceLGF, sourceTempEdge, target;
    
    ArgParser       ap( argc, argv);
    ap.refOption("g", "Graph file of LEMON GRAPH FORMAT", sourceLGF, true);
    ap.refOption("t", "Temporal active edges", sourceTempEdge, true);
    ap.refOption("n", "Target filename", target, true);
    ap.parse();

//    sourceLGF       = "/Users/sonneundasche/Documents/FLI/DATA/02Sheep/Schaf_NEW.lgf";
//    sourceTempEdge  = "/Users/sonneundasche/Documents/FLI/DATA/02Sheep/Schaf_NEW_time_tmpArcIDs.txt";
//        sourceLGF       = "/Users/sonneundasche/Documents/FLI/DATA/03Pork/porkNEW_.lgf";
//        sourceTempEdge  = "/Users/sonneundasche/Documents/FLI/DATA/03Pork/porkNEW__time_tmpArcIDs.txt";
//        target          = "Test";
    
    // ------------------------------
    // --- Graph creation
    // ------------------------------
    cout << "- READING\n";
    ListDigraph                    mGraph;
    try {
        digraphReader(mGraph, sourceLGF)
        .run();
    } catch (lemon::Exception) {
        cerr << "Error reading";
        exit(0);
    }
    
    // ------------------------------
    // --- 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;
//.........这里部分代码省略.........
开发者ID:BildPeter,项目名称:DynamicNetSim,代码行数:101,代码来源:Process_BiggestComponent.cpp


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