1 #ifndef GRAPH_ANALYSIS_NWEIGHTED_HPP 2 #define GRAPH_ANALYSIS_NWEIGHTED_HPP 9 #include <boost/serialization/vector.hpp> 10 #include <boost/archive/text_iarchive.hpp> 11 #include <boost/archive/text_oarchive.hpp> 25 template<
typename T,
size_t Dim,
typename GraphElementType>
29 typedef shared_ptr< NWeighted >
Ptr;
47 NWeighted(
const std::vector<T>& weights = std::vector<T>(Dim))
63 virtual std::string
getClassName()
const {
return "graph_analysis::NWeighted"; }
71 ss << GraphElementType::toString();
73 typename std::vector<T>::const_iterator cit =
mWeights.begin();
103 }
catch(
const std::out_of_range& e)
105 std::stringstream ss;
106 ss <<
"graph_analysis::NWeighted::setWeights: ";
107 ss <<
" dim: is " << Dim <<
", tried access at: " << index;
108 ss <<
": " << std::string(e.what());
109 throw std::out_of_range(ss.str());
120 }
catch(
const std::out_of_range& e)
122 throw std::out_of_range(
"graph_analysis::NWeighted::getWeight: " + std::string(e.what()) );
128 std::stringstream ss;
129 boost::archive::text_oarchive oarch(ss);
136 std::stringstream ss;
138 boost::archive::text_iarchive iarch(ss);
146 if(weights.size() != Dim)
148 std::stringstream ss;
149 ss <<
"graph_analysis::NWeighted: invalid number of weights: expected " << Dim <<
" got " << weights.size();
150 throw std::invalid_argument(ss.str());
160 #endif // GRAPH_ANALYSIS_NWEIGHTED_VERTEX_HPP NWeighted(const std::vector< T > &weights=std::vector< T >(Dim))
Definition: NWeighted.hpp:47
virtual ~NWeighted()
Definition: NWeighted.hpp:59
NWeighted(const T &weight)
Definition: NWeighted.hpp:36
std::vector< T > getWeights() const
Definition: NWeighted.hpp:94
std::string serializeWeights()
Definition: NWeighted.hpp:126
void setWeights(const std::vector< T > &weights)
Definition: NWeighted.hpp:88
const T & getWeight(size_t index=0) const
Definition: NWeighted.hpp:116
shared_ptr< NWeighted > Ptr
Definition: NWeighted.hpp:29
T value_t
Definition: NWeighted.hpp:30
Main namespace of the graph analysis library.
Definition: BFS.cpp:3
NWeighted is a template to associate N-weights with either a vertex or an edge, i.e., adds a vector of weights.
Definition: NWeighted.hpp:26
void setWeight(T value, size_t index=0)
Definition: NWeighted.hpp:99
std::vector< T > mWeights
Definition: NWeighted.hpp:156
virtual GraphElementType * getClone() const
Definition: NWeighted.hpp:154
void deserializeWeights(const std::string &s)
Definition: NWeighted.hpp:134
virtual std::string getClassName() const
Definition: NWeighted.hpp:63
void validateDimensions(const std::vector< T > &weights) const
Definition: NWeighted.hpp:144
virtual std::string toString() const
Definition: NWeighted.hpp:68
NWeighted(const NWeighted &other)
Definition: NWeighted.hpp:54