简体   繁体   中英

boost graph library gives me a compilation add_edge error when I try to create a graph with setS disallowing parallel edges

I tried to create a graph disallowing parallel edges using boost::setS, but it gives me an compilation error...

#include <iostream>
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/graphviz.hpp>
#include <boost/graph/properties.hpp>
#include <boost/property_map/property_map.hpp>
#include <boost/graph/named_function_params.hpp>
#include <boost/graph/iteration_macros.hpp>
#include <random>

struct VertexData
{
long account_id;
};

struct EdgeData
{
//    std::list<long> transaction_ids;
    long edge_id;
};

typedef boost::adjacency_list<boost::vecS, boost::setS,
    boost::directedS,
    VertexData,
    boost::property<boost::edge_weight_t, double, EdgeData>
> MyGraphType;

void test_insert_data(size_t vertex_size, size_t edge_size)
{

std::random_device rd;     // Only used once to initialise (seed) engine
std::mt19937 rng(rd());    // Random-number engine used (Mersenne-Twister in this case)
std::uniform_int_distribution<int> uni(0, vertex_size - 1); // Guaranteed unbiased

auto random_integer = uni(rng);
MyGraphType g;
for (size_t i = 0; i < vertex_size; i++)
    add_vertex(g);
for (size_t j = 0; j < edge_size; j++)
{
    auto from = uni(rng);
    auto to = uni(rng);
    add_edge(from, to, g);
}
}

I got an error below: error: no matching function for call to "add_edge(int&, int&, MyGraphType&)"

But if I switch the boost::setS to boost::vectorS, it works all right.

Please some expert point out where the program goes wrong... Thank you....

sorry I messed up the order of the definition of graph, it should be:

typedef boost::adjacency_list<boost::setS, boost::vecS,
    boost::directedS,
    VertexData,
    boost::property<boost::edge_weight_t, double, EdgeData>
> MyGraphType;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM