atofigh / edmonds-alg

Implementation of maximum branching algorithm (max spanning tree in directed graphs)
MIT License
25 stars 4 forks source link

Core Dump error raised when using the library #3

Open camilleAmaury opened 4 years ago

camilleAmaury commented 4 years ago

Hello,

I'm currently running into a core dump error when I'm trying to use the library.

#include <vector>
#include <algorithm>
#include <iostream>
#include <iterator>
#include <boost/property_map/property_map.hpp>
#include <boost/graph/adjacency_list.hpp>

#include <unistd.h>
#include <fstream>
#include "../../src/edmonds_optimum_branching.hpp"
#include <typeinfo>

using namespace std;

typedef boost::property<boost::edge_weight_t, double>       EdgeProperty;
typedef boost::adjacency_list<boost::listS,
                              boost::vecS,
                              boost::directedS,
                              boost::no_property,
                              EdgeProperty>                 Graph;
typedef boost::graph_traits<Graph>::vertex_descriptor       Vertex;
typedef boost::graph_traits<Graph>::edge_descriptor         Edge;
void process_mem_usage(double& vm_usage, double& resident_set)
{
    vm_usage = 0.0;
    resident_set = 0.0;

    // the two fields we want
    unsigned long vsize;
    long rss;
    {
        std::string ignore;
        std::ifstream ifs("/proc/self/stat", std::ios_base::in);
        ifs >> ignore >> ignore >> ignore >> ignore >> ignore >> ignore >> ignore >> ignore >> ignore >> ignore
                >> ignore >> ignore >> ignore >> ignore >> ignore >> ignore >> ignore >> ignore >> ignore >> ignore
                >> ignore >> ignore >> vsize >> rss;
    }

    long page_size_kb = sysconf(_SC_PAGE_SIZE) / 1024;
    vm_usage = vsize / 1024.0;
    resident_set = rss * page_size_kb;
}
int main(int argc, char *argv[])
{
    const int N = 10;
    Graph G(N);
    vector<Vertex> the_vertices;
    BOOST_FOREACH (Vertex v, vertices(G))
    {
        the_vertices.push_back(v);
    }

    for(int i = 0; i < N; i++){
      double poids = static_cast <double> (rand()) / (static_cast <double> (RAND_MAX/10.0));
      //int poids2 = rand() % 15 + 1;
      add_edge(the_vertices[i], the_vertices[0], poids, G);
    }

    boost::property_map<Graph, boost::edge_weight_t>::type weights = get(boost::edge_weight_t(), G);
    boost::property_map<Graph, boost::vertex_index_t>::type vertex_indices = get(boost::vertex_index_t(), G);

    double vm, rss;
    process_mem_usage(vm, rss);
    cout << "VM: " << vm << "; RSS: " << rss << endl;

    // Find the maximum branching.
    vector<Edge> branching;
    edmonds_optimum_branching<true, false, false>(G,
                                                  vertex_indices,
                                                  weights,
                                                  static_cast<Vertex *>(0),
                                                  static_cast<Vertex *>(0),
                                                  back_inserter(branching));
    cout << "the program worked" << endl;
    return 0;
}

Here is the piece of code, which is really close to the example provided in your files. As you can see, I only try to generate a graph of 10 vertices, with 10 edges which are all directed into the first vertice.

I've randomly generating the edges' weights with 'double' and also i've tried with some 'integer'. I've also check if my memory range was not the problem, but everything looked correct.

Note that, if I change the weight to a fixed value for every edge, I can increase the 'N' variable to 250 until it throws me the same error, which is slighty better but still low in memory storage.

The problem is raised when the function : edmonds_optimum_branching is called

Have you any idea of where the problem could come from ?