glptsp.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /* glptsp.h (TSP format) */
  2. /***********************************************************************
  3. * This code is part of GLPK (GNU Linear Programming Kit).
  4. *
  5. * Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008,
  6. * 2009, 2010 Andrew Makhorin, Department for Applied Informatics,
  7. * Moscow Aviation Institute, Moscow, Russia. All rights reserved.
  8. * E-mail: <mao@gnu.org>.
  9. *
  10. * GLPK is free software: you can redistribute it and/or modify it
  11. * under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation, either version 3 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * GLPK is distributed in the hope that it will be useful, but WITHOUT
  16. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  17. * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
  18. * License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with GLPK. If not, see <http://www.gnu.org/licenses/>.
  22. ***********************************************************************/
  23. #ifndef GLPTSP_H
  24. #define GLPTSP_H
  25. typedef struct TSP TSP;
  26. struct TSP
  27. { /* TSP (or related problem) instance in the format described in
  28. the report [G.Reinelt, TSPLIB 95] */
  29. /*--------------------------------------------------------------*/
  30. /* the specification part */
  31. char *name;
  32. /* identifies the data file */
  33. int type;
  34. /* specifies the type of data: */
  35. #define TSP_UNDEF 0 /* undefined */
  36. #define TSP_TSP 1 /* symmetric TSP */
  37. #define TSP_ATSP 2 /* asymmetric TSP */
  38. #define TSP_TOUR 3 /* collection of tours */
  39. char *comment;
  40. /* additional comments (usually the name of the contributor or
  41. creator of the problem instance is given here) */
  42. int dimension;
  43. /* for a TSP or ATSP, the dimension is the number of its nodes
  44. for a TOUR it is the dimension of the corresponding problem */
  45. int edge_weight_type;
  46. /* specifies how the edge weights (or distances) are given: */
  47. #define TSP_UNDEF 0 /* undefined */
  48. #define TSP_EXPLICIT 1 /* listed explicitly */
  49. #define TSP_EUC_2D 2 /* Eucl. distances in 2-D */
  50. #define TSP_CEIL_2D 3 /* Eucl. distances in 2-D rounded up */
  51. #define TSP_GEO 4 /* geographical distances */
  52. #define TSP_ATT 5 /* special distance function */
  53. int edge_weight_format;
  54. /* describes the format of the edge weights if they are given
  55. explicitly: */
  56. #define TSP_UNDEF 0 /* undefined */
  57. #define TSP_FUNCTION 1 /* given by a function */
  58. #define TSP_FULL_MATRIX 2 /* given by a full matrix */
  59. #define TSP_UPPER_ROW 3 /* upper triangulat matrix (row-wise
  60. without diagonal entries) */
  61. #define TSP_LOWER_DIAG_ROW 4 /* lower triangular matrix (row-wise
  62. including diagonal entries) */
  63. int display_data_type;
  64. /* specifies how a graphical display of the nodes can be
  65. obtained: */
  66. #define TSP_UNDEF 0 /* undefined */
  67. #define TSP_COORD_DISPLAY 1 /* display is generated from the node
  68. coordinates */
  69. #define TSP_TWOD_DISPLAY 2 /* explicit coordinates in 2-D are
  70. given */
  71. /*--------------------------------------------------------------*/
  72. /* data part */
  73. /* NODE_COORD_SECTION: */
  74. double *node_x_coord; /* double node_x_coord[1+dimension]; */
  75. double *node_y_coord; /* double node_y_coord[1+dimension]; */
  76. /* DISPLAY_DATA_SECTION: */
  77. double *dply_x_coord; /* double dply_x_coord[1+dimension]; */
  78. double *dply_y_coord; /* double dply_y_coord[1+dimension]; */
  79. /* TOUR_SECTION: */
  80. int *tour; /* int tour[1+dimension]; */
  81. /* EDGE_WEIGHT_SECTION: */
  82. int *edge_weight; /* int edge_weight[1+dimension*dimension]; */
  83. };
  84. #define tsp_read_data _glp_tsp_read_data
  85. #define tsp_free_data _glp_tsp_free_data
  86. #define tsp_distance _glp_tsp_distance
  87. TSP *tsp_read_data(char *fname);
  88. /* read TSP instance data */
  89. void tsp_free_data(TSP *tsp);
  90. /* free TSP instance data */
  91. int tsp_distance(TSP *tsp, int i, int j);
  92. /* compute distance between two nodes */
  93. #endif
  94. /* eof */