代码中Boost的C ++问题

时间:2018-02-09 23:58:33

标签: c++ boost

这是我正在处理的代码。我一直得到同样的错误,我不知道还有什么办法来解决它。这些是我得到的错误任何帮助将不胜感激。如果我至少可以更好地了解我做错了什么也可能有所帮助。感谢您的时间和提前帮助。

错误:

Error (active)  E0262   not a class or struct name  Main 25 
Error (active)  E1018   namespace "boost" has no member class "default_bfs_visitor" Main 25 
Error (active)  E0020   identifier "kruskal_minimum_spanning_tree" is undefined Main 86 
Error (active)  E0020   identifier "breadth_first_search" is undefined  Main    98  
Error   C2039   'default_bfs_visitor': is not a member of 'boost'   Main 25 
Error   C2504   'default_bfs_visitor': base class undefined Main 26 
Error   C3861   'kruskal_minimum_spanning_tree': identifier not found   Main 86 
Error   C3861   'breadth_first_search': identifier not found    Main 98 

主要代码:

// Main.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include<boost/graph/adjacency_list.hpp>
#include <boost/graph/depth_first_search.hpp>
#include <iostream>

using namespace boost;
using namespace std;
typedef property<edge_weight_t, int> EdgeWeightProperty;
typedef boost::adjacency_list<listS, vecS, directedS, no_property,
        EdgeWeightProperty> Graph;
typedef Graph::edge_descriptor MyEdge;

class my_dfs_visitor: public boost::default_dfs_visitor
{
public:
    template<typename Vertex, typename Graph>
    void discover_vertex(Vertex u, const Graph & g) const
    {
        std::cout << "at " << u << std::endl;
    }
    template<typename Edge, typename Graph>
    void examine_edge(Edge e, const Graph& g) const
    {
        std::cout << "Examining edges " << e << std::endl;
    }
};
class my_bfs_visitor: public boost::default_bfs_visitor
{
public:
    template<typename Vertex, typename Graph>
    void discover_vertex(Vertex u, const Graph & g) const
    {
        std::cout << "at " << u << std::endl;
    }
    template<typename Edge, typename Graph>
    void examine_edge(Edge e, const Graph& g) const
    {
        std::cout << "Examining edges " << e << std::endl;
    }
};

int main()
{
    Graph graph;

//creating 40 edges & 20 vertices using add_edge which accepts parameters as (source vertex, destination vertex, weight, graph object)
    add_edge(0, 3, 8, graph);
    add_edge(1, 4, 18, graph);
    add_edge(2, 5, 28, graph);
    add_edge(3, 6, 82, graph);
    add_edge(4, 7, 81, graph);
    add_edge(5, 8, 9, graph);
    add_edge(6, 9, 7, graph);
    add_edge(7, 18, 80, graph);
    add_edge(8, 20, 7, graph);
    add_edge(9, 10, 84, graph);
    add_edge(10, 19, 48, graph);
    add_edge(11, 10, 56, graph);
    add_edge(12, 17, 53, graph);
    add_edge(13, 17, 2, graph);
    add_edge(14, 16, 1, graph);
    add_edge(15, 17, 3, graph);
    add_edge(16, 2, 4, graph);
    add_edge(17, 5, 9, graph);
    add_edge(18, 4, 7, graph);
    add_edge(19, 3, 85, graph);
    add_edge(20, 1, 11, graph);
    add_edge(0, 20, 8, graph);
    add_edge(1, 19, 18, graph);
    add_edge(2, 18, 28, graph);
    add_edge(3, 17, 82, graph);
    add_edge(4, 16, 81, graph);
    add_edge(5, 15, 9, graph);
    add_edge(6, 14, 7, graph);
    add_edge(7, 13, 80, graph);
    add_edge(8, 12, 7, graph);
    add_edge(9, 11, 84, graph);
    add_edge(10, 11, 48, graph);
    add_edge(11, 9, 56, graph);
    add_edge(12, 8, 53, graph);
    add_edge(13, 7, 2, graph);
    add_edge(14, 6, 1, graph);
    add_edge(15, 5, 3, graph);
    add_edge(16, 4, 4, graph);
    add_edge(17, 3, 9, graph);
    add_edge(18, 2, 7, graph);
    add_edge(19, 1, 85, graph);
    add_edge(20, 3, 11, graph);

//1st Algorithm: Finding Minimum Spanning Tree using Kruskal Algorithm
    std::list<MyEdge> spanningTree;
    kruskal_minimum_spanning_tree(graph, std::back_inserter(spanningTree));
    for (std::list<MyEdge>::iterator e = spanningTree.begin();
            e != spanningTree.end(); ++e)
    {
        cout << *e << " ";
    }
    cout << "\n";

//2nd Algorithm: Depth First Search
    my_dfs_visitor my_visitor;
    depth_first_search(graph, visitor(my_visitor));
//3rd Algorithm: Breadth First Search
    my_bfs_visitor my_visitor_2;
    breadth_first_search(graph, visitor(my_visitor_2));
}

0 个答案:

没有答案