[Résolu] Problème BOOST, C++, NS3

Bonjour,

mon stagiaire rencontre un problème que nous n’arrivons pas à solutionner. Il a préparé un mail pour demander de l’aide sur une mailing list aussi me suis-je dis que la zone dans sa variété de connaissance aurait peut-être une idée.

Si nous devons tout recoder pour nous débarrasser de boost il ne finira jamais son stage de fin d’étude.

C’est un pavé en anglais avec du code mais je préfère ne rien altérer.
Merci d’avance sincérement


Hello,
I am trying to adapt a piece of code in C++ that uses the Boost library, which I know nothing about, and I am encoutering some issues.
More specifically, the original code defines and uses a specific Graph boost type with some C++ classes, MyNode and MyEdge. Some typedefs are defined, and, more importantly, some Boost properties (this is not the whole file, just an extract) :

#include <boost/config.hpp>
#include <boost/property_map/property_map.hpp>
#include <boost/graph/graph_traits.hpp>
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/dijkstra_shortest_paths.hpp>
#include <boost/graph/depth_first_search.hpp>
#include <boost/graph/undirected_dfs.hpp>
#include <boost/pending/indirect_cmp.hpp>

#include <boost/random/linear_congruential.hpp>
#include <boost/random/uniform_int.hpp>
#include <boost/random/uniform_real.hpp>
#include <boost/random/variate_generator.hpp>
#include <boost/generator_iterator.hpp>
namespace boost {
        class MyNode;
        class MyEdge;
	enum vertex_nodeptr_t { vertex_nodeptr };
	BOOST_INSTALL_PROPERTY(vertex, nodeptr);

	enum edge_plc_edgeptr_t { edge_plc_edgeptr };
	BOOST_INSTALL_PROPERTY(edge, plc_edgeptr);

	typedef property<vertex_nodeptr_t, MyNode *, property<vertex_color_t, default_color_type> > VertexProperty;
	typedef property<edge_weight_t, double, property<edge_color_t, default_color_type, property<edge_plc_edgeptr_t, MyEdge *> > > EdgeProperty;


	typedef adjacency_list <vecS, vecS, undirectedS, VertexProperty, EdgeProperty> UGraph;

	typedef std::pair<int, int> Edge;
	typedef graph_traits<UGraph>::vertex_descriptor vertex_descriptor;
	typedef graph_traits<UGraph>::edge_descriptor edge_descriptor;

	typedef property_map<UGraph, vertex_color_t>::type VertexColorMap;
	typedef property_map<UGraph, edge_color_t>::type EdgeColorMap;

	typedef graph_traits<UGraph>::vertex_iterator vertex_iterator;

	typedef property_traits<VertexColorMap>::value_type ColorValue;
	typedef color_traits<ColorValue> Color;

	typedef boost::minstd_rand base_generator_type;

	typedef boost::uniform_int<> distribution_type;
	typedef boost::variate_generator<boost::base_generator_type&, distribution_type> gen_type;
}

As I said, I am adapting this original module and for that, I need to use my own classes MyNewNode and MyNewEdge instead respectively of MyNode and MyEdge., for my new module (my own version). So I adapted the code as follows :

namespace boost {
        class MyNewNode;
        class MyNewEdge;

	enum vertex_nodeptr_new_t { vertex_nodeptr_new };
	BOOST_INSTALL_PROPERTY(vertex, nodeptr_new);

	enum edge_plc_edgeptr_new_t { edge_plc_edgeptr_new };
	BOOST_INSTALL_PROPERTY(edge, plc_edgeptr_new);

	typedef property<vertex_nodeptr_new_t, MyNewNode *, property<vertex_color_t, default_color_type> > NewVertexProperty;
	typedef property<edge_weight_t, double, property<edge_color_t, default_color_type, property<edge_plc_edgeptr_new_t, MyNewEdge *> > > NewEdgeProperty;


	typedef adjacency_list <vecS, vecS, undirectedS, NewVertexProperty, NewEdgeProperty> NewUGraph;

	typedef std::pair<int, int> NewEdge;
	typedef graph_traits<NewUGraph>::vertex_descriptor vertex_descriptor_new;
	typedef graph_traits<NewUGraph>::edge_descriptor edge_descriptor_new;

	typedef property_map<NewUGraph, vertex_color_t>::type NewVertexColorMap;
	typedef property_map<NewUGraph, edge_color_t>::type NewEdgeColorMap;

	typedef graph_traits<NewUGraph>::vertex_iterator vertex_iterator;

	typedef property_traits<NewVertexColorMap>::value_type NewColorValue;
	typedef color_traits<NewColorValue> NewColor;

	typedef boost::minstd_rand base_generator_type_new;

	typedef boost::uniform_int<> distribution_type_new;
	typedef boost::variate_generator<boost::base_generator_type&, distribution_type> gen_type_new;
}

I would like, in the ideal case, that both modules (the original one and the new one) can be used at the same time if need be, but remain independent, this is why I do not only change MyNode into MyNewNode and MyEdge in MyNewEdge in the code, but also rename (with the …_new… and the New…) everything else.
By doing so, and replacing all corresponding names in the .h and .cc files where they are used (that is, I do not change the logic at all, I do absolutely the same things than in the original module, same functions but just with the new objects), gcc does compile. Wheter I disable the original module (then none of its source files are taken into account) or not. But I get an error at run time, on a boost function. That error obviously does not happen with the original module where everything works perfectly fine. I will not give the detail that I get on run time, because I think that it does not really matter in detail, but I would rather need help on how to proceed when it comes to «adapt» a boost graph / define a new boost graph.
So, here come the questions :
I do not really know how the whole BOOST_INSTALL_PROPERTY thing work. Is what I did (the replacing) theoretically correct? Can I install these properties, with these newly defined enums, or am I doing something wrong here? Is it OK to use the _new and New… objects in replacements of the old ones in the files where the old ones are used, or do I need to do something else?
From what I understood from the documentation, you can install properties on 3 types of «objects», vertex, edge and another one, so I have to manipulate these things, I do not need to define my own vertex so that I would need to call a BOOST_INSTALL_PROPERTY(my_own_vertex, my_enum), right?

Classes MyNewNode and MyNewEdge both have at least the same class members than MyNode and MyEdge (MyNewStuff could inherit from MyStuff if I did not want both modules to be able to be independent), and there is nothing regarding boost in MyNode and MyEdge. As I said earlier, at run time, problem comes from boost (at least, the instruction that cannot be executed is a boost one).
I believe that the problem comes from this adaptation of mine, but of course I can be wrong (I would not behere otherwise). If you see nothing wrong with what I did, I can provide you with the source files, but they are heavy to use since both modules are developed for the ns-3 simulator. If we come to this, should I try and reproduce the problem without ns-3 so that it is easier for you to work on it?
I am on Linux Ubuntu 15.04, 64 bits.
Thanks a lot, guys!

C’est dommage, c’est la premiere question que j’allais poser. C’est quoi l’erreur ?
Si c’est une accessviolation ou un pure virtual fonction call, c’est pas la meme chose.

Apres, je connais pas trop boost, mais il doit juste lui manquer un truc, genre un functor ou autre qu’il resolve au runtime.

Et pour ceux qu’un diff tenterait, sans les includes, ca donnerait ca : https://www.diffchecker.com/ctni1ezh

Bon je vais éditer le thread mon stagiaire à juste fait une petite erreur pas compliqué mais au dessus de laquelle tous le monde était passé.

En tout cas merci @AnA-l :smiley:

Hein ? J’ai rien fait moi !

Mais je veux bien la reponse :slight_smile:

Je lui demande de me copier les deux lignes où il a fait l’erreur et je te dis ça :slight_smile:

Edit: En gros il essayait d’accéder à des nodes d’un graph qui étaient vides :slight_smile: le problème lambda, mais au final lui et 2 autres personnes étaient passer à côté. Si tu veux je peux te coller l’erreur boost mais au final l’erreur était sur le NS-3

En gros l’erreur était plus fonctionnelle que technique ?

Interface chaise clavier, pour changer :smiley:

c’est ça.

Faut supprimer les intermédiaires. L’interface entre la chaise et le clavier. Et la chaise et le clavier !