estar/CSpace.hpp

Go to the documentation of this file.
00001 /* 
00002  * Copyright (C) 2007 Roland Philippsen <roland dot philippsen at gmx net>
00003  * 
00004  * This program is free software; you can redistribute it and/or modify
00005  * it under the terms of the GNU General Public License as published by
00006  * the Free Software Foundation; either version 2 of the License, or
00007  * (at your option) any later version.
00008  * 
00009  * This program is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  * 
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software
00016  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00017  * USA
00018  */
00019 
00020 
00021 #ifndef ESTAR_CSPACE_HPP
00022 #define ESTAR_CSPACE_HPP
00023 
00024 
00025 #include <estar/base.hpp>
00026 
00027 
00028 namespace estar {
00029   
00030   
00031   struct vertex_read_iteration
00032   {
00033     vertex_it vi, vi_end;
00034     
00035     vertex_read_iteration(cspace_t const & cspace)
00036     { boost::tie(vi, vi_end) = boost::vertices(cspace); }
00037     
00038     vertex_read_iteration & operator ++ () { ++vi; return *this; }
00039     
00040     vertex_t operator * () const { return *vi; }
00041     
00042     bool at_end() const { return vi == vi_end; }
00043     
00044     bool not_at_end() const { return vi != vi_end; }
00045     
00046     template<typename some_map_t>
00047     typename some_map_t::value_type get(some_map_t const & some_map) const
00048     { return boost::get(some_map, *vi); }
00049   };
00050   
00051   
00052   struct edge_read_iteration
00053   {
00054     adjacency_it ei, ei_end;
00055     
00056     edge_read_iteration(cspace_t const & cspace, vertex_t from)
00057     { boost::tie(ei, ei_end) = boost::adjacent_vertices(from, cspace); }
00058     
00059     edge_read_iteration & operator ++ () { ++ei; return *this; }
00060     
00061     vertex_t operator * () const { return *ei; }
00062     
00063     bool at_end() const { return ei == ei_end; }
00064     
00065     bool not_at_end() const { return ei != ei_end; }
00066     
00067     template<typename some_map_t>
00068     typename some_map_t::value_type get(some_map_t const & some_map) const
00069     { return boost::get(some_map, *ei); }
00070   };
00071   
00072   
00078   class BaseCSpace
00079   {
00080   public:
00081     BaseCSpace();
00082     
00084     vertex_read_iteration begin() const
00085     { return vertex_read_iteration(m_cspace); }
00086     
00088     edge_read_iteration begin(vertex_t from) const
00089     { return edge_read_iteration(m_cspace, from); }
00090     
00091     double GetValue(vertex_t vertex) const;
00092     double GetMeta(vertex_t vertex) const;
00093     double GetRhs(vertex_t vertex) const;
00094     flag_t GetFlag(vertex_t vertex) const;
00095     
00096     const cspace_t & GetGraph() const { return m_cspace; }
00097     const value_map_t & GetValueMap() const { return m_value; }
00098     const meta_map_t & GetMetaMap() const { return m_meta; }
00099     const rhs_map_t & GetRhsMap() const { return m_rhs; }
00100     const flag_map_t & GetFlagMap() const { return m_flag; }
00101     const vertexid_map_t & GetVertexIdMap() const { return m_vertexid; }
00102 
00103     void SetValue(vertex_t vertex, double value);
00104     void SetMeta(vertex_t vertex, double meta);
00105     void SetRhs(vertex_t vertex, double rhs);
00106     void SetFlag(vertex_t vertex, flag_t flag);
00107     
00108     cspace_t & GetGraph() { return m_cspace; }
00109     value_map_t & GetValueMap() { return m_value; }
00110     meta_map_t & GetMetaMap() { return m_meta; }
00111     rhs_map_t & GetRhsMap() { return m_rhs; }
00112     flag_map_t & GetFlagMap() { return m_flag; }
00113     vertexid_map_t & GetVertexIdMap() { return m_vertexid; }
00114     
00121     void AddNeighbor(vertex_t from, vertex_t to);
00122     
00123     
00124   protected:
00125     cspace_t m_cspace;
00126     value_map_t m_value;
00127     meta_map_t m_meta;
00128     rhs_map_t m_rhs;
00129     flag_map_t m_flag;
00130     vertexid_map_t m_vertexid;
00131     
00142     vertex_t
00143     AddVertex(
00146               double value,
00154               double meta,
00162               double rhs,
00166               flag_t flag);
00167   };
00168   
00169   
00170   class CSpace
00171     : public BaseCSpace
00172   {
00173   public:
00174     vertex_t AddVertex(double value = infinity,
00175                        double meta = 1,
00176                        double rhs = infinity,
00177                        flag_t flag = NONE)
00178     { return BaseCSpace::AddVertex(value, meta, rhs, flag); }
00179   };
00180   
00181 
00186   template<typename custom_t>
00187   class CustomCSpace
00188     : public BaseCSpace
00189   {
00190   public:
00191     typedef custom_t vertex_data_t;
00192     
00193     custom_t & Lookup (vertex_t vertex)
00194     { return boost::get(m_custom_map, vertex); }
00195     
00196     custom_t const & Lookup (vertex_t vertex) const
00197     { return boost::get(m_custom_map, vertex); }
00198     
00199     vertex_t AddVertex(custom_t custom,
00200                        double value = infinity,
00201                        double meta = 1,
00202                        double rhs = infinity,
00203                        flag_t flag = NONE)
00204     {
00205       vertex_t const vertex(BaseCSpace::AddVertex(value, meta, rhs, flag));
00206       m_custom_vector.push_back(custom);
00207       m_custom_map = custom_map_t(m_custom_vector.begin(), m_vertexid);
00208       return vertex;
00209     }
00210     
00211   protected:
00212     typedef std::vector<custom_t> custom_vector_t;
00213     typedef typename custom_vector_t::iterator custom_iterator_t;
00214     typedef boost::iterator_property_map<custom_iterator_t,
00215                                          vertexid_map_t> custom_map_t;
00216     
00217     custom_vector_t m_custom_vector;
00218     custom_map_t m_custom_map;
00219   };
00220   
00221   
00222 } // namespace estar
00223 
00224 #endif // ESTAR_CSPACE_HPP

doxygen SourceForge.net Logo
E* Interpolated Graph Replanner Wed Dec 12 18:55:40 2007