TSPLIB
|
00001 00012 #ifndef _ValidateGraph_HPP_ 00013 #define _ValidateGraph_HPP_ 00014 00015 #include <vector> 00016 #include <sstream> 00017 00018 00022 class GraphNotValid { 00023 public: 00027 inline GraphNotValid() { 00028 } 00029 }; 00030 00035 class Graph { 00036 private: 00044 bool isUndirected; 00045 00049 std::vector<std::vector<double> >::size_type n; 00050 00058 std::vector<std::vector<double> > adjacencyMatrix; 00059 00060 protected: 00067 inline void setAdjacencyMatrixElement( 00068 const std::vector<std::vector<double> >::size_type i, 00069 const std::vector<double>::size_type j, 00070 const double value) { 00071 adjacencyMatrix.at(i).at(j) = value; 00072 } 00073 00080 inline double getAdjacencyMatrixElement( 00081 const std::vector<std::vector<double> >::size_type i, 00082 const std::vector<double>::size_type j) const { 00083 return (adjacencyMatrix.at(i).at(j)); 00084 } 00085 00086 public: 00095 Graph(const std::vector<std::vector<double> > &adjacencyMatrix); 00096 00101 Graph(const Graph &graph); 00102 00108 Graph &operator=(const Graph &graph); 00109 00116 friend std::ostream &operator<<(std::ostream &os, Graph &graph); 00117 00126 inline bool getIsUndirected() const { 00127 return (isUndirected); 00128 } 00129 00134 inline std::vector<std::vector<double> >::size_type getN() const { 00135 return (n); 00136 } 00137 00144 inline double getEdgeCost( 00145 const std::vector<std::vector<double> >::size_type i, 00146 const std::vector<double>::size_type j) const { 00147 if (isUndirected) { 00148 if (i < j) { 00149 return (getAdjacencyMatrixElement(j, i)); 00150 } 00151 else { 00152 return (getAdjacencyMatrixElement(i, j)); 00153 } 00154 } 00155 else { 00156 return (getAdjacencyMatrixElement(i, j)); 00157 } 00158 } 00159 }; 00160 00161 00162 #endif