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


C++ AdjacencyList::getGraph方法代码示例

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


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

示例1: calculateRec

//Faire un autre avec un K a décrémenter à chaque appel recursif;
std::vector<Vertex*> AVC::calculate(AdjacencyList& graph) {
    vector<int>* vertexCover;
    vector<Vertex*> vc;
    vector<int> vertexDeleted;
    calculateRec(graph, vertexCover, vertexDeleted);
    if (vertexCover != NULL){
        cout << "Vertex cover de taille: " << vertexCover->size() << endl;
        for (auto i : *vertexCover){
            //Copie des adresses des vertex dans le vector
            vc.push_back(&graph.getGraph().at(i));
        }
        return vc;
    } else {
        return NULL;
    }
}
开发者ID:orichalque,项目名称:VertexCover,代码行数:17,代码来源:AVC.cpp

示例2: while

std::vector<Vertex*> GreedyVC::calculate(AdjacencyList& graph) {
    vector<int> VC;
    cout << "Step 1" << endl;
    vector<Edge> E; //copy graphe edges;
    
    
    for (auto it = graph.getEdges() -> begin(); it != graph.getEdges()->end(); it++){
        Edge edgeToCopy;
        edgeToCopy.debut = it -> debut;
        edgeToCopy.fin = it -> fin;
        E.push_back(edgeToCopy);
    }
    
    vector<Edge> E2;
    
    random_device r;
    std::default_random_engine e1(r());
    uniform_int_distribution<int>* uid;
    Edge currentEdge;
    cout << "Step 2: debut de la boucle" << endl;
    
    while (!E.empty()){
        //Choix de l'arete a ajouter
        uid = new uniform_int_distribution<int>(0, E.size()-1);
        int pos = uid -> operator ()(e1);
        currentEdge = E.at(pos);
        
        
        cout << "Edge: " << currentEdge.debut << " - " << currentEdge.fin << endl;
        //Ajout des deux vertex de l'arete au VC
        VC.push_back(currentEdge.debut);
        VC.push_back(currentEdge.fin);
        
        cout << "Step 3 : Vertex adjacent a u" << endl;
        
        for (int i = 0; i < graph.getGraph()[currentEdge.debut].adjacentVertex.size(); ++i){
            Edge edgeCovered;
            edgeCovered.debut = currentEdge.debut;
            edgeCovered.fin = graph.getGraph()[currentEdge.debut].adjacentVertex[i]->num;
            if (! (edgeCovered == currentEdge)){
                E2.push_back(edgeCovered);
            }    
        }
        
        
        cout << "Step 4 : Vertex adjacent a v" << endl;
        for (int i = 0; i < graph.getGraph()[currentEdge.fin].adjacentVertex.size(); ++i){
            Edge edgeCovered;
            edgeCovered.debut = currentEdge.fin;
            edgeCovered.fin = graph.getGraph()[currentEdge.fin].adjacentVertex[i]->num;
            if (! (edgeCovered == currentEdge)){
                E2.push_back(edgeCovered);
            }    
        }
        
        
        E.erase(E.begin()+pos);
        
        
        cout << "Step 5 : Suppression de E' " << endl;
        for (auto edgeToRemove : E2){
            auto it = find(E.begin(), E.end(), edgeToRemove);
            if (it != E.end()){
                E.erase(it);
            }
        }
        
        E2.clear();               
        //pick edges in E
        //V' += E.vertex
        //E' = Aretes incidentes au vertex de E
        //E -= E'
    }
    
    vector<Vertex*> vcToReturn;
    cout << VC.size() << " solutions trouvées pour Vertex Cover: " << endl;
    
    for (auto v : VC){
        cout << graph.getGraph().at(v).num << " ";   
        vcToReturn.push_back(&graph.getGraph().at(v));
    }
    cout << endl;
    return vcToReturn;
    
}
开发者ID:orichalque,项目名称:VertexCover,代码行数:85,代码来源:GreedyVC.cpp


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