[vector, PropertyGraph] Problem declaring a class member of the "vector<int>" type
Hello everyone,
I am trying to declare, in a header file, a class that has a member of type "vector<double>" (the code is included below). The compiler complains that I haven't included the appropriate namespace (the error message reads, "ISO C++ forbids declaration of ‘vector’ with no type"), and I understand that it is looking for this:
using namespace boost::numeric::ublas;
However, I tried putting it in the header file in various places (haven't programmed in C++ in 10 years and couldn't find any online documentation to clarify this specific situation), and still no luck. I am definitely doing something wrong, but cannot reason out the error, as it probably has to do with the specific syntax conventions. Any help is appreciated!
Thanks, -Al
P.S. Code in header file:
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // File "airspace-graph-rectilinear-edges.h" typedef char* string; const int PHYSICAL_SPACE_DIMENSION = 2; // Information needed about a waypoint used in an airspace: name and physical position class WaypointConcept{ private: using namespace boost::numeric::ublas; string waypoint_name; vector<double> waypoint_position_xyh(PHYSICAL_SPACE_DIMENSION); public: string GetWaypointName(); vector<double> GetWaypointPosition(); }
class AirspaceGraphConcept PropertyGraphConcept<class Graph, class WaypointConcept, class vertex_index_t>; typedef Vertex* GraphPathType; typedef string FlightIDType; typedef boost::unordered_map<std::FlightIDType, GraphPathType> FlightIDToPathAssignmentType; //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Code in the .cpp file (which includes the above header file) I am trying to compile: ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// #include <boost/lambda/lambda.hpp> #include <iostream> #include <iterator> #include <algorithm> #include <boost/numeric/ublas/io.hpp> #include <boost/numeric/ublas/vector.hpp> #include "airspace-graph-rectilinear-edges.h"
int main() { using namespace boost::numeric::ublas;
vector<double> v(3); for (unsigned i = 0; i < v.size(); ++ i) v (i) = 2.01*double(i); std::cout << v << std::endl; } //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Alex Sadovsky <a_sadovsky@yahoo.com> writes:
Hello everyone,
I am trying to declare, in a header file, a class that has a member of type "vector<double>" (the code is included below). ?The compiler complains that I haven't included the appropriate namespace (the error message reads, "ISO C++ forbids declaration of ?vector? with no type"), and I understand that it is looking for this:
using namespace boost::numeric::ublas;
However, I tried putting it in the header file in various places (haven't programmed in C++ in 10 years and couldn't find any online documentation to clarify this specific situation), and still no luck. ?I am definitely doing something wrong, but cannot reason out the error, as it probably has to do with the specific syntax conventions. ?Any help is appreciated!
Thanks, -Al
P.S. ?Code in header file:
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // ?File "airspace-graph-rectilinear-edges.h" typedef char* string; const int PHYSICAL_SPACE_DIMENSION = 2; // ?Information needed about a waypoint used in an airspace: name and physical position class WaypointConcept{ ?private: ??using namespace boost::numeric::ublas; ??string waypoint_name; ??vector<double> waypoint_position_xyh(PHYSICAL_SPACE_DIMENSION); ?public: ??string GetWaypointName(); ??vector<double> GetWaypointPosition(); }
class AirspaceGraphConcept PropertyGraphConcept<class Graph, class WaypointConcept, class vertex_index_t>; typedef Vertex* GraphPathType; ? typedef string FlightIDType; typedef boost::unordered_map<std::FlightIDType, GraphPathType> FlightIDToPathAssignmentType; //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Code in the .cpp file (which includes the above header file) I am trying to compile: ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// #include <boost/lambda/lambda.hpp> #include <iostream> #include <iterator> #include <algorithm> #include <boost/numeric/ublas/io.hpp> #include <boost/numeric/ublas/vector.hpp> #include "airspace-graph-rectilinear-edges.h"
int main() { ????using namespace boost::numeric::ublas;
????vector<double> v(3); ????for (unsigned i = 0; i < v.size(); ++ i) ??????v (i) = 2.01*double(i); ???? ????std::cout << v << std::endl; } //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
You seem to missing an #include <vector> and vector should be qualified as std::vector<double>. Also, I'd consider typedef char* string; to be moderately evil given that there is a type std::string. HTH, Philipp Moeller
Thanks much. ________________________________ From: Philipp Moeller <philipp.moeller@geometryfactory.com> To: boost-users@lists.boost.org Sent: Friday, March 9, 2012 2:47 PM Subject: Re: [Boost-users] [vector, PropertyGraph] Problem declaring a class member of the "vector<int>" type Alex Sadovsky <a_sadovsky@yahoo.com> writes:
Hello everyone,
I am trying to declare, in a header file, a class that has a member of type "vector<double>" (the code is included below). ?The compiler complains that I haven't included the appropriate namespace (the error message reads, "ISO C++ forbids declaration of ?vector? with no type"), and I understand that it is looking for this:
using namespace boost::numeric::ublas;
However, I tried putting it in the header file in various places (haven't programmed in C++ in 10 years and couldn't find any online documentation to clarify this specific situation), and still no luck. ?I am definitely doing something wrong, but cannot reason out the error, as it probably has to do with the specific syntax conventions. ?Any help is appreciated!
Thanks, -Al
P.S. ?Code in header file:
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // ?File "airspace-graph-rectilinear-edges.h" typedef char* string; const int PHYSICAL_SPACE_DIMENSION = 2; // ?Information needed about a waypoint used in an airspace: name and physical position class WaypointConcept{ ?private: ??using namespace boost::numeric::ublas; ??string waypoint_name; ??vector<double> waypoint_position_xyh(PHYSICAL_SPACE_DIMENSION); ?public: ??string GetWaypointName(); ??vector<double> GetWaypointPosition(); }
class AirspaceGraphConcept PropertyGraphConcept<class Graph, class WaypointConcept, class vertex_index_t>; typedef Vertex* GraphPathType; ? typedef string FlightIDType; typedef boost::unordered_map<std::FlightIDType, GraphPathType> FlightIDToPathAssignmentType; //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Code in the .cpp file (which includes the above header file) I am trying to compile: ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// #include <boost/lambda/lambda.hpp> #include <iostream> #include <iterator> #include <algorithm> #include <boost/numeric/ublas/io.hpp> #include <boost/numeric/ublas/vector.hpp> #include "airspace-graph-rectilinear-edges.h"
int main() { ????using namespace boost::numeric::ublas;
????vector<double> v(3); ????for (unsigned i = 0; i < v.size(); ++ i) ??????v (i) = 2.01*double(i); ???? ????std::cout << v << std::endl; } //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
You seem to missing an #include <vector> and vector should be qualified as std::vector<double>. Also, I'd consider typedef char* string; to be moderately evil given that there is a type std::string. HTH, Philipp Moeller _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
Hello, I have defined a directed graph type, and a path type (each variable of type "path" is a sequence (vector) of vertices in the graph such that every two consecutive ones are connected by an edge). Each path is parameterized by arc length. What I'd like to do is tabulate the function that, for each pair (vertex, path) tells the arc length coordinate of the vertex. I don't want to make it a function: a pair (vertex, path) is likely to come up more than once, and I want to avoid repeating the computation of the arc length coordinate. Just compute it once and store it in a property map. The code for the above definitions is below (P.S.). Any help greatly appreciated. Thanks, Alex P.S. typedef boost::numeric::ublas::vector<double> EuclideanVector_t; typedef std::size_t VertexIndex_t; // Information needed about a vertex: name and physical position struct VertexProperties { VertexIndex_t VertexIndex; std::string VertexName; EuclideanVector_t VertexPhysicalPosition; }; struct EdgeProperties { double EdgeEuclideanLength; EuclideanVector_t EdgeUnitDirector; }; // graph type (vertices are points in a Euclidean space, edges are rectilinear segments) typedef boost::adjacency_list<boost::vecS, boost::listS, boost::directedS, VertexProperties, EdgeProperties> GraphRectilinearEdges_t; // Vertex iterator type typedef boost::graph_traits<GraphRectilinearEdges_t>::vertex_iterator GraphVertexIterator_t; // Edge iterator type typedef boost::graph_traits<GraphRectilinearEdges_t>::edge_iterator GraphEdgeIterator_t; // A path is a sequence of vertices in the Graph, implemented as vector whose entries are vertex indices class GraphPath_t { private: boost::numeric::ublas::vector<VertexIndex_t>; double PathLength; public: };
On Tue, 12 Jun 2012, Alex Sadovsky wrote:
Hello,
I have defined a directed graph type, and a path type (each variable of type "path" is a sequence (vector) of vertices in the graph such that every two consecutive ones are connected by an edge). Each path is parameterized by arc length.
What I'd like to do is tabulate the function that, for each pair (vertex, path) tells the arc length coordinate of the vertex. I don't want to make it a function: a pair (vertex, path) is likely to come up more than once, and I want to avoid repeating the computation of the arc length coordinate. Just compute it once and store it in a property map.
Where are you storing the paths? Are they attached to vertices? They don't appear to be from the definitions below. Are you going to be using all of the <vertex, path> pairs' arc length values? I don't think I fully understand what you're asking---why do you want to store your data in a property map? What are you thinking of as the keys of the property map? Vertices, or <vertex, path> pairs, or something else? -- Jeremiah Willcock
Reply to boost-users@lists.boost.org ________________________________ From: Jeremiah Willcock <jewillco@osl.iu.edu> To: "boost-users@lists.boost.org" <boost-users@lists.boost.org> Sent: Wednesday, June 13, 2012 11:10 AM Subject: Re: [Boost-users] [PropertyMap, Graph] Question on constructing a property map from a Cartesian product AxB of two sets to the set C of all real numbers On Tue, 12 Jun 2012, Alex Sadovsky wrote:
Hello,
I have defined a directed graph type, and a path type (each variable of type "path" is a sequence (vector) of vertices in the graph such that every two consecutive ones are connected by an edge). Each path is parameterized by arc length.
What I'd like to do is tabulate the function that, for each pair (vertex, path) tells the arc length coordinate of the vertex. I don't want to make it a function: a pair (vertex, path) is likely to come up more than once, and I want to avoid repeating the computation of the arc length coordinate. Just compute it once and store it in a property map.
Where are you storing the paths? Are they attached to vertices? They don't appear to be from the definitions below. Are you going to be using all of the <vertex, path> pairs' arc length values? I don't think I fully understand what you're asking---why do you want to store your data in a property map? What are you thinking of as the keys of the property map? Vertices, or <vertex, path> pairs, or something else? -- Jeremiah Willcock _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
Hi Jeremiah, Thanks for reading, and apologies for lack of clarity. Let me provide the clarifications. The keys to the map will be the pairs <vertex, path>. The value corresponding to such a key is the arc length coordinate of that vertex on that path. I will likely be needing the values for most of the keys and, more importantly, will need to access repeatedly the value for a given key. This need for repeated access the main reason for wanting to store the values in a property map rather than compute them every time using a function. The paths will be stored in instances of a different class. I am modeling the movement of a collection of ``moving agents'' (vehicles , robots, etc.) in a network (graph), each agent assigned to a path in the graph. I will have a class defining a moving agent. One of the class variables will be the path to which that agent is assigned. I hope this clarifies my intentions, but if it doesn't, I'll gladly answer further questions. Thanks again, Alex ________________________________ From: Jeremiah Willcock <jewillco@osl.iu.edu> To: "boost-users@lists.boost.org" <boost-users@lists.boost.org> Sent: Wednesday, June 13, 2012 11:10 AM Subject: Re: [Boost-users] [PropertyMap, Graph] Question on constructing a property map from a Cartesian product AxB of two sets to the set C of all real numbers On Tue, 12 Jun 2012, Alex Sadovsky wrote:
Hello,
I have defined a directed graph type, and a path type (each variable of type "path" is a sequence (vector) of vertices in the graph such that every two consecutive ones are connected by an edge). Each path is parameterized by arc length.
What I'd like to do is tabulate the function that, for each pair (vertex, path) tells the arc length coordinate of the vertex. I don't want to make it a function: a pair (vertex, path) is likely to come up more than once, and I want to avoid repeating the computation of the arc length coordinate. Just compute it once and store it in a property map.
Where are you storing the paths? Are they attached to vertices? They don't appear to be from the definitions below. Are you going to be using all of the <vertex, path> pairs' arc length values? I don't think I fully understand what you're asking---why do you want to store your data in a property map? What are you thinking of as the keys of the property map? Vertices, or <vertex, path> pairs, or something else? -- Jeremiah Willcock _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
On Wed, 13 Jun 2012, Alex Sadovsky wrote:
Hi Jeremiah,
Thanks for reading, and apologies for lack of clarity. Let me provide the clarifications.
The keys to the map will be the pairs <vertex, path>. The value corresponding to such a key is the arc length coordinate of that vertex on that path. I will likely be needing the values for most of the keys and, more importantly, will need to access repeatedly the value for a given key. This need for repeated access the main reason for wanting to store the values in a property map rather than compute them every time using a function.
The paths will be stored in instances of a different class. I am modeling the movement of a collection of ``moving agents'' (vehicles , robots, etc.) in a network (graph), each agent assigned to a path in the graph. I will have a class defining a moving agent. One of the class variables will be the path to which that agent is assigned.
I hope this clarifies my intentions, but if it doesn't, I'll gladly answer further questions.
OK. Unless you need to use these maps in BGL algorithms or have a generic interface, you might want to just use an std::map, hash table, or similar to store your data. If you do want to use a property map, use associative_property_map unless you have some way to map your paths to a dense interval of integers (which you probably don't, but you might if you have a finite, known set of them). -- Jeremiah Willcock
____________________________________________________________________________________________________________________________________________________________ From: Jeremiah Willcock <jewillco@osl.iu.edu> To: "boost-users@lists.boost.org" <boost-users@lists.boost.org> Sent: Wednesday, June 13, 2012 11:10 AM Subject: Re: [Boost-users] [PropertyMap, Graph] Question on constructing a property map from a Cartesian product AxB of two sets to the set C of all real numbers
On Tue, 12 Jun 2012, Alex Sadovsky wrote:
Hello,
I have defined a directed graph type, and a path type (each variable of type "path" is a sequence (vector) of vertices in the graph such that every two consecutive ones are connected by an edge). Each path is parameterized by arc length.
What I'd like to do is tabulate the function that, for each pair (vertex, path) tells the arc length coordinate of the vertex. I don't want to make it a function: a pair (vertex, path) is likely to come up more than once, and I want to avoid repeating the computation of the arc length coordinate. Just compute it once and store it in a property map.
Where are you storing the paths? Are they attached to vertices? They don't appear to be from the definitions below. Are you going to be using all of the <vertex, path> pairs' arc length values? I don't think I fully understand what you're asking---why do you want to store your data in a property map? What are you thinking of as the keys of the property map? Vertices, or <vertex, path> pairs, or something else?
-- Jeremiah Willcock _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
participants (3)
-
Alex Sadovsky
-
Jeremiah Willcock
-
Philipp Moeller