TSPLIB
|
00001 00014 #include <cmath> 00015 00016 #include "ValidateInstance.hpp" 00017 00018 using namespace std; 00019 00020 00021 void Instance::init( 00022 const std::string &name, 00023 const std::string &source, 00024 const std::string &description, 00025 const std::streamsize doublePrecision, 00026 const std::streamsize ignoredDigits, 00027 const Graph &graph) { 00028 this->name = name; 00029 this->source = source; 00030 this->description = description; 00031 this->doublePrecision = doublePrecision; 00032 this->ignoredDigits = ignoredDigits; 00033 this->doubleZero = pow(10, -1.0 * static_cast<double>(doublePrecision - ignoredDigits)); 00034 this->graph = new Graph(graph); 00035 } 00036 00037 Instance::Instance( 00038 const std::string &name, 00039 const std::string &source, 00040 const std::string &description, 00041 const std::streamsize doublePrecision, 00042 const std::streamsize ignoredDigits, 00043 const Graph &graph) { 00044 this->graph = 0; 00045 try { 00046 init(name, source, description, doublePrecision, ignoredDigits, graph); 00047 } 00048 catch (bad_alloc &e) { 00049 if (this->graph != 0) { 00050 delete this->graph; 00051 } 00052 throw; 00053 } 00054 } 00055 00056 Instance::Instance(const Instance &instance) { 00057 graph = 0; 00058 try { 00059 init( 00060 instance.getName(), 00061 instance.getSource(), 00062 instance.getDescription(), 00063 instance.getDoublePrecision(), 00064 instance.getIgnoredDigits(), 00065 *instance.getGraph()); 00066 } 00067 catch (bad_alloc &e) { 00068 if (graph != 0) { 00069 delete graph; 00070 } 00071 throw; 00072 } 00073 } 00074 00075 Instance::~Instance() { 00076 if (graph != 0) { 00077 delete graph; 00078 } 00079 } 00080 00081 Instance &Instance::operator=(const Instance &instance) { 00082 if (this == &instance) { 00083 return (*this); 00084 } 00085 else { 00086 graph = 0; 00087 try { 00088 init( 00089 instance.getName(), 00090 instance.getSource(), 00091 instance.getDescription(), 00092 instance.getDoublePrecision(), 00093 instance.getIgnoredDigits(), 00094 *instance.getGraph()); 00095 } 00096 catch (bad_alloc &e) { 00097 if (graph != 0) { 00098 delete graph; 00099 } 00100 throw; 00101 } 00102 00103 return (*this); 00104 } 00105 } 00106 00107 std::ostream &operator<<(std::ostream &os, Instance &instance) { 00108 os << "<"; 00109 os << "name: " << instance.getName() << endl; 00110 os << "source: " << instance.getSource() << endl; 00111 os << "description: " << instance.getDescription() << endl; 00112 os << "doublePrecision: " << instance.getDoublePrecision() << endl; 00113 os << "ignoredDigits: " << instance.getIgnoredDigits() << endl; 00114 os << "doubleZero: " << instance.getDoubleZero() << endl; 00115 os << "graph: " << *instance.getGraph(); 00116 os << ">" << endl; 00117 00118 return (os); 00119 }