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


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

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


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

示例1: calculateRec

bool AVC::calculateRec(AdjacencyList& graph, std::vector<int>* vertexCover, std::vector<int> deleted) {
    if (vertexCover != NULL){
        return false;
    }
    if (graph.getEdges()->empty()){
        vertexCover = &deleted;
        return true;
    }
    
    random_device r;
    std::default_random_engine e1(r());
    uniform_int_distribution<int>* uid;
    uid = new uniform_int_distribution<int>(0, graph.getEdges()->size());
    Edge e = graph.getEdges()->at(uid -> operator ()(e1));
    
    //Choisir arete aléatoire
    //Construire graphe G1 sans le vertex u, et graphe G2 sans le vertex v
    //return fonction sur G1 v G2
    
}
开发者ID:orichalque,项目名称:VertexCover,代码行数:20,代码来源: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::getEdges方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。