TSPLIB
Classes | Functions | Variables
src/TransformConstantsClassesAndFunctions.hpp File Reference

Defines the constants, types and some functions necessary for the transform programs. More...

#include <cmath>
#include <string>
#include <vector>
#include <iomanip>
#include <xercesc/util/PlatformUtils.hpp>

Go to the source code of this file.

Classes

class  InputFileFormatNotSupported
class  TransformInstance

Functions

void trimLeft (std::string &s, const std::string &t=" \t\r\n")
void trimRight (std::string &s, const std::string &t=" \t\r\n")
void trim (std::string &s, const std::string &t=" \t\r\n")
double roundToDoublePrecisionAndDoubleFloatField (double d)
TransformInstancereadInputFileTSPLIB (const std::string &inputFileName)
void writeOutputFile (const std::string &outputFileName, const TransformInstance *transformInstance)
void writeOutputFileWithoutUsingAParser (const std::string &outputFileName, const TransformInstance *transformInstance)

Variables

const std::string INPUT_FILE_FILENAME_EXTENSION_TSP = ".tsp"
const std::string INPUT_FILE_FILENAME_EXTENSION_ATSP = ".atsp"
const std::string TAG_NAME = "NAME:"
const std::string TAG_TYPE = "TYPE:"
const std::string TAG_COMMENT = "COMMENT:"
const std::string TAG_DIMENSION = "DIMENSION:"
const std::string TAG_EDGE_WEIGHT_TYPE = "EDGE_WEIGHT_TYPE:"
const std::string TAG_EDGE_WEIGHT_FORMAT = "EDGE_WEIGHT_FORMAT:"
const std::string TAG_DISPLAY_DATA_TYPE = "DISPLAY_DATA_TYPE:"
const std::string TAG_NODE_COORD_SECTION = "NODE_COORD_SECTION"
const std::string EDGE_WEIGHT_SECTION = "EDGE_WEIGHT_SECTION"
const std::string DISPLAY_DATA_SECTION = "DISPLAY_DATA_SECTION"
const std::string TAG_EOF = "EOF"
const std::string VALUE_TYPE_TSP = "TSP"
const std::string VALUE_TYPE_ATSP = "ATSP"
const double RRR = 6378.388
const std::string VALUE_EDGE_WEIGHT_TYPE_GEO = "GEO"
const std::string VALUE_EDGE_WEIGHT_TYPE_EUC_2D = "EUC_2D"
const std::string VALUE_EDGE_WEIGHT_TYPE_CEIL_2D = "CEIL_2D"
const std::string VALUE_EDGE_WEIGHT_TYPE_ATT = "ATT"
const std::string VALUE_EDGE_WEIGHT_TYPE_EXPLICIT = "EXPLICIT"
const std::string VALUE_EDGE_WEIGHT_FORMAT_FUNCTION = "FUNCTION"
const std::string VALUE_EDGE_WEIGHT_FORMAT_FULL_MATRIX = "FULL_MATRIX"
const std::string VALUE_EDGE_WEIGHT_FORMAT_LOWER_DIAG_ROW = "LOWER_DIAG_ROW"
const std::string VALUE_EDGE_WEIGHT_FORMAT_UPPER_DIAG_ROW = "UPPER_DIAG_ROW"
const std::string VALUE_EDGE_WEIGHT_FORMAT_UPPER_ROW = "UPPER_ROW"
const std::string VALUE_DISPLAY_DATA_TYPE_COORD_DISPLAY = "COORD_DISPLAY"
const std::string VALUE_DISPLAY_DATA_TYPE_TWOD_DISPLAY = "TWOD_DISPLAY"
const std::string OUTPUT_FILE_FILENAME_EXTENSION = ".xml"
const bool XML_FORMAT_PRETTY_PRINT = true
const std::string XML_DOCUMENT_NODE = "travellingSalesmanProblemInstance"
const std::string XML_NAME = "name"
const std::string XML_SOURCE = "source"
const std::string XML_DESCRIPTION = "description"
const std::string XML_DOUBLE_PRECISION = "doublePrecision"
const std::string XML_IGNORED_DIGITS = "ignoredDigits"
const std::string XML_GRAPH = "graph"
const std::string XML_VERTEX = "vertex"
const std::string XML_EDGE = "edge"
const std::string XML_EDGE_ATTRIBUTE_COST = "cost"
const std::string XML_ENCODING = "UTF-8"
const std::string XML_VALUE_SOURCE_TSPLIB = "TSPLIB"
const std::ios::fmtflags DOUBLE_FLOATFIELD = std::ios::scientific
const std::streamsize TRANSFORM_DOUBLE_PRECISION = std::numeric_limits<double>::digits10
const std::streamsize TRANSFORM_IGNORED_DIGITS = 5
const double TRANSFORM_DOUBLE_ZERO

Detailed Description

Defines the constants, types and some functions necessary for the transform programs.

Defines the constants, classes and some functions necessary for the transform programs.

Author:
Ulrich Pferschy and Rostislav Stanek (Institut fuer Statistik und Operations Research, Universitaet Graz)

Definition in file TransformConstantsClassesAndFunctions.hpp.


Function Documentation

TransformInstance* readInputFileTSPLIB ( const std::string &  inputFileName)

Reads the input file and creates an instance of the class TransformInstance. The parameters are not checked. Every keyword must be on a new line and is allowed to be used only once. Note that the symbol ":" has to follow the keywords immediately. The order possibilities of the input keywords are: 1) "NAME:", "TYPE:" (= "TSP"), "COMMENT:", "DIMENSION:", "EDGE_WEIGHT_TYPE:" (= "GEO"), ("EDGE_WEIGHT_FORMAT:" (= "FUNCTION"),) DISPLAY_DATA_TYPE:" (= "COORD_DISPLAY"), "NODE_COORD_SECTION", coordinates, "EOF", 2) "NAME:", "TYPE:", "COMMENT:", "DIMENSION:", "EDGE_WEIGHT_TYPE:" (= "EUC_2D" / "CEIL_2D"), "NODE_COORD_SECTION", coordinates, "EOF", 3) "NAME:", "TYPE:", "COMMENT:", "DIMENSION:", "EDGE_WEIGHT_TYPE:" (= "ATT"), "NODE_COORD_SECTION", coordinates, "EOF", 4) "NAME:", "TYPE:" (= "TSP"), "COMMENT:", "DIMENSION:", "EDGE_WEIGHT_TYPE:" (= "EXPLICIT"), "EDGE_WEIGHT_FORMAT:" (= "FULL_MATRIX"), "EDGE_WEIGHT_SECTION", matrix entries, "EOF", 5) "NAME:", "TYPE:" (= "TSP"), "COMMENT:", "DIMENSION:", "EDGE_WEIGHT_TYPE:" (= "EXPLICIT"), "EDGE_WEIGHT_FORMAT:" (= "FULL_MATRIX"), "TAG_DISPLAY_DATA_TYPE" (= "TWOD_DISPLAY"), "EDGE_WEIGHT_SECTION", matrix entries, DISPLAY_DATA_SECTION, coordinates, "EOF", 6) "NAME:", "TYPE:" (= "TSP"), "COMMENT:", "DIMENSION:", "EDGE_WEIGHT_TYPE:" (= "EXPLICIT"), "EDGE_WEIGHT_FORMAT:" (= "LOWER_DIAG_ROW"), "EDGE_WEIGHT_SECTION", matrix entries, "EOF", 7) "NAME:", "TYPE:" (= "TSP"), "COMMENT:", "DIMENSION:", "EDGE_WEIGHT_TYPE:" (= "EXPLICIT"), "EDGE_WEIGHT_FORMAT:" (= "LOWER_DIAG_ROW"), "TAG_DISPLAY_DATA_TYPE" (= "TWOD_DISPLAY"), "EDGE_WEIGHT_SECTION", matrix entries, DISPLAY_DATA_SECTION, coordinates, "EOF", 8) "NAME:", "TYPE:" (= "TSP"), "COMMENT:", "DIMENSION:", "EDGE_WEIGHT_TYPE:" (= "EXPLICIT"), "EDGE_WEIGHT_FORMAT:" (= "UPPER_ROW"), "EDGE_WEIGHT_SECTION", matrix entries, "EOF", 9) "NAME:", "TYPE:" (= "TSP"), "COMMENT:", "DIMENSION:", "EDGE_WEIGHT_TYPE:" (= "EXPLICIT"), "EDGE_WEIGHT_FORMAT:" (= "UPPER_ROW"), "TAG_DISPLAY_DATA_TYPE" (= "TWOD_DISPLAY"), "EDGE_WEIGHT_SECTION", matrix entries, DISPLAY_DATA_SECTION, coordinates, "EOF", 10) "NAME:", "TYPE:" (= "ATSP"), "COMMENT:", "DIMENSION:", "EDGE_WEIGHT_TYPE:" (= "EXPLICIT"), "EDGE_WEIGHT_FORMAT:" (= "FULL_MATRIX"), "NODE_COORD_SECTION", matrix entries, "EOF".

Parameters:
inputFileNameName of the input file.
Returns:
Instance of the class TransformInstance.
double roundToDoublePrecisionAndDoubleFloatField ( double  d) [inline]

Rounds the double to the TRANSFORM_DOUBLE_PRECISION. The floatfield is set to DOUBLE_FLOATFIELD (see IOConstantsBasicFunctionsAndBasicClasses.hpp).

Parameters:
dNumber which should be rounded.
Returns:
Rounded number d.

Definition at line 299 of file TransformConstantsClassesAndFunctions.hpp.

References DOUBLE_FLOATFIELD, and TRANSFORM_DOUBLE_PRECISION.

Referenced by TransformInstance::setAdjacencyMatrixElement().

void trim ( std::string &  s,
const std::string &  t = " \t\r\n" 
) [inline]

Trims the string from left and from right.

Parameters:
sThe string.
tThe trimmed characters.

Definition at line 288 of file TransformConstantsClassesAndFunctions.hpp.

References trimLeft(), and trimRight().

Referenced by SAX2ContentHandler::characters(), SAX2ContentHandler::endElement(), readInputFileTSPLIB(), and SAX2ContentHandler::startElement().

void trimLeft ( std::string &  s,
const std::string &  t = " \t\r\n" 
) [inline]

Trims the string from left.

Parameters:
sThe string.
tThe trimmed characters.

Definition at line 264 of file TransformConstantsClassesAndFunctions.hpp.

Referenced by trim().

void trimRight ( std::string &  s,
const std::string &  t = " \t\r\n" 
) [inline]

Trims the string from right.

Parameters:
sThe string.
tThe trimmed characters.

Definition at line 273 of file TransformConstantsClassesAndFunctions.hpp.

Referenced by trim().

void writeOutputFile ( const std::string &  outputFileName,
const TransformInstance transformInstance 
)

Writes one instance of the class TransformInstance to an output file. The parameters are not checked.

Parameters:
outputFileNameName of the output file.
transformInstanceInstance of the class TransformInstance.
void writeOutputFileWithoutUsingAParser ( const std::string &  outputFileName,
const TransformInstance transformInstance 
)

Writes one instance of the class TransformInstance to an output file without using a parser. This method is quicker than the previous one but it provides no parser guarantee that the output file is a valid xml file. The parameters are not checked.

Parameters:
outputFileNameName of the output file.
transformInstanceInstance of the class TransformInstance.

Definition at line 1525 of file TransformConstantsClassesAndFunctions.cpp.

References DOUBLE_FLOATFIELD, TransformInstance::getAdjacencyMatrixElement(), TransformInstance::getDescription(), TransformInstance::getN(), TransformInstance::getName(), TransformInstance::getType(), TRANSFORM_DOUBLE_PRECISION, TRANSFORM_IGNORED_DIGITS, and VALUE_TYPE_ATSP.

Referenced by main().


Variable Documentation

const std::string DISPLAY_DATA_SECTION = "DISPLAY_DATA_SECTION"

Tag for the TSPLIB: "DISPLAY_DATA_SECTION".

Definition at line 82 of file TransformConstantsClassesAndFunctions.hpp.

Referenced by readInputFileTSPLIB().

const std::ios::fmtflags DOUBLE_FLOATFIELD = std::ios::scientific

Floatfield flag of doubles writed to stringstreams.

Definition at line 239 of file TransformConstantsClassesAndFunctions.hpp.

Referenced by roundToDoublePrecisionAndDoubleFloatField(), writeOutputFile(), and writeOutputFileWithoutUsingAParser().

const std::string EDGE_WEIGHT_SECTION = "EDGE_WEIGHT_SECTION"

Tag for the TSPLIB: "EDGE_WEIGHT_SECTION".

Definition at line 77 of file TransformConstantsClassesAndFunctions.hpp.

Referenced by readInputFileTSPLIB().

const std::string INPUT_FILE_FILENAME_EXTENSION_ATSP = ".atsp"

Filename extension for the asymmetric travelling salesman problem files from the TSPLIB.

Definition at line 32 of file TransformConstantsClassesAndFunctions.hpp.

Referenced by main(), and readInputFileTSPLIB().

const std::string INPUT_FILE_FILENAME_EXTENSION_TSP = ".tsp"

Filename extension for the symmetric travelling salesman problem files from the TSPLIB.

Definition at line 27 of file TransformConstantsClassesAndFunctions.hpp.

Referenced by main(), and readInputFileTSPLIB().

const std::string OUTPUT_FILE_FILENAME_EXTENSION = ".xml"

Filename extension for xml files.

Definition at line 168 of file TransformConstantsClassesAndFunctions.hpp.

Referenced by main().

const double RRR = 6378.388

Idealized sphere radius of the earth.

Definition at line 102 of file TransformConstantsClassesAndFunctions.hpp.

Referenced by readInputFileTSPLIB().

const std::string TAG_COMMENT = "COMMENT:"

Tag for the TSPLIB: "COMMENT:".

Definition at line 47 of file TransformConstantsClassesAndFunctions.hpp.

Referenced by readInputFileTSPLIB().

const std::string TAG_DIMENSION = "DIMENSION:"

Tag for the TSPLIB: "DIMENSION:".

Definition at line 52 of file TransformConstantsClassesAndFunctions.hpp.

Referenced by readInputFileTSPLIB().

const std::string TAG_DISPLAY_DATA_TYPE = "DISPLAY_DATA_TYPE:"

Tag for the TSPLIB: "DISPLAY_DATA_TYPE:".

Definition at line 67 of file TransformConstantsClassesAndFunctions.hpp.

Referenced by readInputFileTSPLIB().

const std::string TAG_EDGE_WEIGHT_FORMAT = "EDGE_WEIGHT_FORMAT:"

Tag for the TSPLIB: "EDGE_WEIGHT_FORMAT:".

Definition at line 62 of file TransformConstantsClassesAndFunctions.hpp.

Referenced by readInputFileTSPLIB().

const std::string TAG_EDGE_WEIGHT_TYPE = "EDGE_WEIGHT_TYPE:"

Tag for the TSPLIB: "EDGE_WEIGHT_TYPE:".

Definition at line 57 of file TransformConstantsClassesAndFunctions.hpp.

Referenced by readInputFileTSPLIB().

const std::string TAG_EOF = "EOF"

Tag for the TSPLIB: "EOF:".

Definition at line 87 of file TransformConstantsClassesAndFunctions.hpp.

Referenced by readInputFileTSPLIB().

const std::string TAG_NAME = "NAME:"

Tag for the TSPLIB: "NAME":.

Definition at line 37 of file TransformConstantsClassesAndFunctions.hpp.

Referenced by readInputFileTSPLIB().

const std::string TAG_NODE_COORD_SECTION = "NODE_COORD_SECTION"

Tag for the TSPLIB: "NODE_COORD_SECTION".

Definition at line 72 of file TransformConstantsClassesAndFunctions.hpp.

Referenced by readInputFileTSPLIB().

const std::string TAG_TYPE = "TYPE:"

Tag for the TSPLIB: "TYPE:".

Definition at line 42 of file TransformConstantsClassesAndFunctions.hpp.

Referenced by readInputFileTSPLIB().

const std::streamsize TRANSFORM_DOUBLE_PRECISION = std::numeric_limits<double>::digits10

Precision of doubles writed to the .xml-files.

Definition at line 244 of file TransformConstantsClassesAndFunctions.hpp.

Referenced by roundToDoublePrecisionAndDoubleFloatField(), writeOutputFile(), and writeOutputFileWithoutUsingAParser().

const double TRANSFORM_DOUBLE_ZERO
Initial value:
                pow(10.0, -1.0 * static_cast<double>(TRANSFORM_DOUBLE_PRECISION - TRANSFORM_IGNORED_DIGITS))

Maximum of an absolute value considered as zero used by "Transform"-classes.

Definition at line 255 of file TransformConstantsClassesAndFunctions.hpp.

Referenced by readInputFileTSPLIB().

const std::streamsize TRANSFORM_IGNORED_DIGITS = 5

Number of ignored digits of double types. (The deviation of double values can be at most 1e-(DoublePrecision - IgnoredDigits).)

Definition at line 250 of file TransformConstantsClassesAndFunctions.hpp.

Referenced by writeOutputFile(), and writeOutputFileWithoutUsingAParser().

const std::string VALUE_DISPLAY_DATA_TYPE_COORD_DISPLAY = "COORD_DISPLAY"

Value "COORD_DISPLAY" for the tag "VALUE_DISPLAY_DATA_TYPE:" for the TSPLIB.

Definition at line 157 of file TransformConstantsClassesAndFunctions.hpp.

Referenced by readInputFileTSPLIB().

const std::string VALUE_DISPLAY_DATA_TYPE_TWOD_DISPLAY = "TWOD_DISPLAY"

Value "COORD_DISPLAY" for the tag "VALUE_DISPLAY_DATA_TYPE:" for the TSPLIB.

Definition at line 162 of file TransformConstantsClassesAndFunctions.hpp.

Referenced by readInputFileTSPLIB().

const std::string VALUE_EDGE_WEIGHT_FORMAT_FULL_MATRIX = "FULL_MATRIX"

Value "FUNCTION" for the tag "EDGE_WEIGHT_FORMAX:" for the TSPLIB.

Definition at line 137 of file TransformConstantsClassesAndFunctions.hpp.

Referenced by readInputFileTSPLIB().

const std::string VALUE_EDGE_WEIGHT_FORMAT_FUNCTION = "FUNCTION"

Value "FUNCTION" for the tag "EDGE_WEIGHT_FORMAT:" for the TSPLIB.

Definition at line 132 of file TransformConstantsClassesAndFunctions.hpp.

Referenced by readInputFileTSPLIB().

const std::string VALUE_EDGE_WEIGHT_FORMAT_LOWER_DIAG_ROW = "LOWER_DIAG_ROW"

Value "FUNCTION" for the tag "EDGE_WEIGHT_FORMAX:" for the TSPLIB.

Definition at line 142 of file TransformConstantsClassesAndFunctions.hpp.

Referenced by readInputFileTSPLIB().

const std::string VALUE_EDGE_WEIGHT_FORMAT_UPPER_DIAG_ROW = "UPPER_DIAG_ROW"

Value "FUNCTION" for the tag "EDGE_WEIGHT_FORMAX:" for the TSPLIB.

Definition at line 147 of file TransformConstantsClassesAndFunctions.hpp.

Referenced by readInputFileTSPLIB().

const std::string VALUE_EDGE_WEIGHT_FORMAT_UPPER_ROW = "UPPER_ROW"

Value "FUNCTION" for the tag "EDGE_WEIGHT_FORMAX:" for the TSPLIB.

Definition at line 152 of file TransformConstantsClassesAndFunctions.hpp.

Referenced by readInputFileTSPLIB().

const std::string VALUE_EDGE_WEIGHT_TYPE_ATT = "ATT"

Value "GEO" for the tag "EDGE_WEIGHT_TYPE:" for the TSPLIB.

Definition at line 122 of file TransformConstantsClassesAndFunctions.hpp.

Referenced by readInputFileTSPLIB().

const std::string VALUE_EDGE_WEIGHT_TYPE_CEIL_2D = "CEIL_2D"

Value "CEIL_2D" for the tag "EDGE_WEIGHT_TYPE:" for the TSPLIB.

Definition at line 117 of file TransformConstantsClassesAndFunctions.hpp.

Referenced by readInputFileTSPLIB().

const std::string VALUE_EDGE_WEIGHT_TYPE_EUC_2D = "EUC_2D"

Value "EUC_2D" for the tag "EDGE_WEIGHT_TYPE:" for the TSPLIB.

Definition at line 112 of file TransformConstantsClassesAndFunctions.hpp.

Referenced by readInputFileTSPLIB().

const std::string VALUE_EDGE_WEIGHT_TYPE_EXPLICIT = "EXPLICIT"

Value "EXPLICIT" for the tag "EDGE_WEIGHT_TYPE:" for the TSPLIB.

Definition at line 127 of file TransformConstantsClassesAndFunctions.hpp.

Referenced by readInputFileTSPLIB().

const std::string VALUE_EDGE_WEIGHT_TYPE_GEO = "GEO"

Value "GEO" for the tag "EDGE_WEIGHT_TYPE:" for the TSPLIB.

Definition at line 107 of file TransformConstantsClassesAndFunctions.hpp.

Referenced by readInputFileTSPLIB().

const std::string VALUE_TYPE_ATSP = "ATSP"

Value for the tag "TYPE:" for the asymmetric travelling salesman problem.

Definition at line 97 of file TransformConstantsClassesAndFunctions.hpp.

Referenced by readInputFileTSPLIB(), writeOutputFile(), and writeOutputFileWithoutUsingAParser().

const std::string VALUE_TYPE_TSP = "TSP"

Value for the tag "TYPE:" for the symmetric travelling salesman problem.

Definition at line 92 of file TransformConstantsClassesAndFunctions.hpp.

Referenced by TransformInstance::getAdjacencyMatrixElement(), readInputFileTSPLIB(), TransformInstance::setAdjacencyMatrixElement(), and TransformInstance::TransformInstance().

const std::string XML_DESCRIPTION = "description"

Xml tag: Description of the instance.

Definition at line 193 of file TransformConstantsClassesAndFunctions.hpp.

Referenced by SAX2ContentHandler::endElement(), and writeOutputFile().

const std::string XML_DOCUMENT_NODE = "travellingSalesmanProblemInstance"

Xml tag: Name of the document node.

Definition at line 178 of file TransformConstantsClassesAndFunctions.hpp.

Referenced by writeOutputFile().

const std::string XML_DOUBLE_PRECISION = "doublePrecision"

Precision of doubles.

Definition at line 198 of file TransformConstantsClassesAndFunctions.hpp.

Referenced by SAX2ContentHandler::endElement(), and writeOutputFile().

const std::string XML_EDGE = "edge"
const std::string XML_EDGE_ATTRIBUTE_COST = "cost"

Xml tag - attribute: Cost of the edge.

Definition at line 224 of file TransformConstantsClassesAndFunctions.hpp.

Referenced by writeOutputFile().

const std::string XML_ENCODING = "UTF-8"

Encoding of the xml file

Definition at line 229 of file TransformConstantsClassesAndFunctions.hpp.

Referenced by writeOutputFile().

const bool XML_FORMAT_PRETTY_PRINT = true

The output will be pretty printed

Definition at line 173 of file TransformConstantsClassesAndFunctions.hpp.

Referenced by writeOutputFile().

const std::string XML_GRAPH = "graph"

Xml tag: Underlying graph.

Definition at line 209 of file TransformConstantsClassesAndFunctions.hpp.

Referenced by SAX2ContentHandler::endElement(), and writeOutputFile().

const std::string XML_IGNORED_DIGITS = "ignoredDigits"

Number of ignored digits of double types. (The deviation of double values can be at most 1e-(DoublePrecision - IgnoredDigits).)

Definition at line 204 of file TransformConstantsClassesAndFunctions.hpp.

Referenced by SAX2ContentHandler::endElement(), and writeOutputFile().

const std::string XML_NAME = "name"

Xml tag: Name of the instance.

Definition at line 183 of file TransformConstantsClassesAndFunctions.hpp.

Referenced by SAX2ContentHandler::endElement(), and writeOutputFile().

const std::string XML_SOURCE = "source"

Xml tag: Source of the instance.

Definition at line 188 of file TransformConstantsClassesAndFunctions.hpp.

Referenced by SAX2ContentHandler::endElement(), and writeOutputFile().

const std::string XML_VALUE_SOURCE_TSPLIB = "TSPLIB"

Value "TSPLIB" for the xml tag "source"

Definition at line 234 of file TransformConstantsClassesAndFunctions.hpp.

Referenced by readInputFileTSPLIB().

const std::string XML_VERTEX = "vertex"
 All Classes Files Functions Variables Friends Defines